1st Level – Survive ================================================================================ i → Insert mode. Type ESC to return to Normal mode x → Delete the char under the cursor :wq → Save and Quit (:w save, :q quit) dd → Delete (and copy) current line p → Paste
hjkl → basic cursor move (←↓↑→) :help → Show help about , you can start using :help without anything else. ================================================================================
2nd Level – Feel comfortable ================================================================================ 1. Insert mode variations: a → insert after the cursor o → insert a new line after the current one O → insert a new line before the current one cw → replace from the cursor to the end the word
2. Basic moves 0 → go to first column ^ → go to first non-blank character of the line $ → go to the end of line g_ → go to the last non-blank character of line /pattern → search for pattern
3. Copy/Paste P → paste before, remember p is paste after current position. yy → copy current line, easier but equivalent to ddP
4. Undo/Redo u → undo → redo
5. Load/Save/Quit/Change File (Buffer) :e → open :w → save :saveas → save to :x, ZZ or :wq → save and quit (:x only save if necessary) :q! → quit without saving, also :qa! to even if there are some modified hidden buffers. :bn (resp. :bp) → show next (resp.previous) file (buffer) ================================================================================
3rd Level – Better. Stronger. Faster. ================================================================================ Better Let’s look at how vim could help you to repeat yourself: . → (dot) will repeat the last command N → will do the command N times Some examples, open a file and type: 2dd → will delete 2 lines 3p → will paste the text 3 times 100idesu [ESC] → will write desu 100 times 3. → Will write 3 “desu” (and not 300, how clever).
Stronger Knowing how to move efficiently with vim is very important. NG → Go to line N gg → shortcut for 1G, go to the start of the file G → Go to last line Word moves: word: composed of letter and the underscore character WORD: a group of letter separated by blank characters w → go to the start of the following word e → go to the end of this word W → go to the start of the following WORD E → go to the end of this WORD
Now let’s talk about very efficient moves: % → Go to corresponding (, {, [. * (resp. #) : go to next (resp. previous) occurrence of the word under the cursor
Faster Most commands can be used using the following general format: For example : 0y$ means 0 → go to the beginning of this line y → yank from here $ → up to the end of this line But what was true for y (yank), is also true for d (delete), v(visual select), gU (uppercase), gu (lowercase), etc... 0y$ → copy this line 0d$ → delete this line 0v$ → select this line 0gU$ → change this line to upper case 0gu$ → change this line to lower case gggUG → change all text to upper case ================================================================================
4th Level – Vim Superpowers ================================================================================ Move on current line: 0 ^ $ f F t T , ; 0 → go to column 0 ^ → go to first character on the line $ → go to the last character on the line fa → go to next occurrence of the letter a on the line. (resp. ;) will seek for the next (resp. previous) occurrence. t, → go just before the character , 3fa → search the 3rd occurrence of a on this line F and T → like f and t but backward. A useful tip is: dt" → remove everything until the "
Zone selection a Where action can be any action, for example, d (delete), y(yank), v (select in visual mode). And object can be: w a word, W a WORD (extended word), s a sentence, p a paragraph. But also, natural character such as " , ' , ) , } , ] .
Suppose the cursor is on the first o of (map (+) ("foo")) . vi" → will select foo. va" → will select "foo". vi) → will select "foo". va) → will select ("foo"). v2i) → will select map (+) ("foo") v2a) → will select (map (+) ("foo"))
Select rectangular blocks: . Rectangular blocks are very useful to comment many lines of code. enable column select mode. Typically: 0I-- [ESC] 0 → go to start of the line → Start block selection → move down (could also be jjj or %, etc...) I-- [ESC] → write -- to comment each line
Completion: and . In Insert mode, just type the start of a word, then type or , can auto complete the word which has been occured before. For example: this th
Visual selection: v,V, v → normal select mode. → column select mode. Add something at the end of all visually selected lines: go to desired line (jjj or or /pattern or % etc...) $ go to the end of line A, write text, ESC.
Splits: split and vsplit :split → create a horizontal split. :vsplit → create a vertical split. → where direction is any of hjkl or ←↓↑→ to change split.