Vim for everyone!
This is a vim-neovim tutorial, is a highly-configurable text editor that you can make it as you wish, and the way to use it is only with the keyboard and keybindings and learning it will improve your productivity at a whole other level, and it is included in every UNIX system and Mac OS, so if you configure servers remotely or work a lot in the terminal is really important to use vim, and you can add plugins and make a lot of cool stuff with it!
1.0 Installing vim
The first step into the rabbit hole, here it goes!
sudo apt in vim
sudo dnf in vim
sudo pacman -S vim
1.1 Vim modes
Vim has three modes and each one of the three you can escape them with ESC:
- Normal mode: You use it to navegate in the editor, you should be in this mode the most of the time.
- Insert mode: In this mode you can type text into the file, type
Ito enter insert mode.
- Visual mode: In this mode you can select large chunks of text, to copy, paste, cut, etc…
1.2 Quitting vim
There are different ways of quitting vim, but these are the most important:
:q!= Quit and don’t save changes
:wq= Write and quit
:x= Exits the file, if the file has changes it will save them.
1.3 Useful shortcuts to use
- To quickly go to the initial character of the line =
- To go to the first line of the document =
- To go to the last line of the document =
- To go to a particular line of the document =
10G(10 is the number of the line you want to go)
- To go to the most near parenthesis use =
- To execute a command inside vim =
- Vim can help you if you don’t remember a command! just use
ctrl+dwhen writing a command, for example you want to write and quit but don’t remember how, just press the inital letter and then
1.4 Deleting, undoing and redoing!
- To delete the character that the cursor is selecting =
xif you want to delete more than one character you can by doing so =
4x(Knowing that the 4 is the quantity of characters you want to be deleted)
- To undo what you did use =
- The same principal tackles undo with multiple times =
- To redo, just use =
- To delete word by word use =
- To delete line by line use =
- To delete backawards word use =
- To delete from the cursor until the end of the line use =
1.5 Navigating more in-depth
- To navigate word by word use =
w(ends of the beginning of each word)
- If we want to navigate word by word ending on the last character of the word use =
- Mix it up! navigate between quantity of words =
- Go backawards =
- Navigate by visual lines! Vim is made to navigate (h,j,k,l) in logical lines, where it’s supposed to help when inserting, but if you want to navigate for reading use =
gj(gj being visual down)
emore in-depth: when navigating with this keys, the commas, parenthesis, etc, are counted as a word, but if we don’t want that just capitalize it! =
- Forwarding to navigate to a specific character, for example move the cursor where a letter t is =
- Forwarding in reverse! =
- Forwarding until, forward until you find a certain character, landing the cursor before that character =
- Forwarding until in reverse =
- Inserting without caring about blank characters, inserting to the first non-blank character =
- Navigating between blocks of text, being next blank line use =
- Navigating between blocks of text, being the previous blank line use =
1.6 Replacing, appending and changing
- You mistyped something? Not to worry with the replace function! it replaces the character where the cursor is and then press it replacement =
- If you want to change something, you can with the change function, where it changes the character before the cursor, for example let’s change a word, remember to exit out of insert mode, let’s use =
- Let’s change a entire line! use =
- Let’s append to a line, since inserting is always before the cursor, append to insert after the cursor =
- Append to the last character of the line =
- To delete a character and start in insert mode use =
- To delete a entire line and start in insert mode use =
- To insert on the line below use =
- To insert on the line above being on the line that you are use =
1.7 Yanking and putting!
- Yanking is copying in vim, so for example let’s yank a word! =
- What if you want to delete something and put in on other line? =
p(For example, you delete a line
ddand put it three lines below
- Yank from the cursor till the end of the line with =
- Remember that cutting in vim is just deleting and putting it
1.8 Searching in your document
/and then the word you want to search!
- If you have multiple instances of that word, you can use
nto go next or
Nto go backawards
- When searching to go back to where you started, and if pressed again to the beginning of the file, use =
- If I want to go forward where I was use =
- Replace your finding! press
s/finding/replacement/gfollowing the formula!
- Replacing in the entire document, formula =
- Replacing in the entire document with a yes/no prompt =
- Replacing each instance between lines =
Reminder: Remember to mix it up!
You can mix numbers with hotkeys, for example if you want to delete 10 lines you aren’t going to press
dd 10 times, just multiply it!
10dd and so on and so forth with the others! Mix it up!
This is for now! these are the essential vim hotkeys and commands to survive and to start into the rabbit hole, expect more of vim in my blog thank you for reading!