Get Started. It's Free
or sign up with your email address
VIM by Mind Map: VIM

1. 1- Basic Editing

1.1. Insert Mode vs Normal Mode

1.1.1. In Normal mode the keystrokes are commands

1.1.2. To go to instert mode type i

1.1.3. To go back to Normal mode type <Esc> (maybe twice)

1.2. Moving around using hjkl

1.2.1. the keys are on the home row of your right hand

1.2.2. l is on the right, h is on the left, j points down

1.3. Delete character with x

1.4. Delete line with dd

1.5. Join two lines with J

1.6. Undo the ``last edit'' with u

1.7. Redo the last undo with CTRL-R

1.8. Undos all the changes on the last edited line with U

1.8.1. U is an edit command which `u' undos and CTRL-R redos

1.9. Append with `a'

1.9.1. Same as i but puts you just after the character

1.10. Open a new line with `o'

1.11. Add a count before commands to increase their effects

1.11.1. 3k moves you three lines down

1.11.2. 3ahello<Esc> appends three times hello

1.11.3. The count always comes before the command it modifies

1.12. Write and exit with ZZ

1.12.1. This will only close the current window (might not exit vim itself)

1.13. Find help with :help

1.13.1. Jump to a |tag| with CTRL-] Jump back with CTRL-T (pop tag) or CTRL-O (go to previous position)

1.13.2. :help {subject} :help subject() function subject :help E43 for error number 43 :help i_<Up> for insert mode up arrow :help 'number' for editor option 'number' :help -t for command line switch -t :help i_CTRL-H for insert mode command CTRL-H :help CTRL-H for normal mode command CTRL-H :help c_abc for command line mode command abc :help abc for normal mode command abc :help helpfile.txt goes to the top of a help file

1.14. `:scriptnames' the list of all the start-up script files

2. 2- Moving Around

2.1. Moving around a line with `$' `^' and '0' (zero)

2.1.1. `$' to the end of the line

2.1.2. `^' to the first non-black char of a line

2.1.3. `0' To the the very first char of a line (even if blank)

2.2. Moving to a specific line with `G' and `gg'

2.2.1. `33G' takes you to line 33

2.2.2. `G' takes you to the last line

2.2.3. `gg' takes you to the first line

2.3. Matching parenthesis with `%'

2.3.1. `%' moves to the matching closing/openning parenthesis in an expression

2.3.2. If not on a parenthesis, `%' moves forward to the next one

2.3.3. Define what constitutes a parenthesis with the option `matchpairs'

2.4. Moving to specific characters in a line with f/F and t/T

2.4.1. `fx' moves to the next x in the line

2.4.2. `Fx' moved to the previous x in the line

2.4.3. t and T are the same except they stop just before the target

2.4.4. These commands never cross lines

2.4.5. You can add counts: 3fx (to the third x)

2.4.6. Repeat these commands with `;'. Repeat in the other direction with ','

2.5. Moving aournd words with w/b and e/ge

2.5.1. Next word start `w' You can move 3 words forward with 3w This command moves to the start of the next word

2.5.2. Previous word start `b' Moves to the previous word start

2.5.3. Next word end `e'

2.5.4. Previous word end `ge'

2.5.5. These commands will move you across lines

2.5.6. To move by WHITE SPACE separated words use W/B and E/gE

2.6. Moving around the screen with `H/M/L'

2.6.1. 'H' to first visible line on the screen

2.6.2. 'M' to middle of the screen

2.6.3. 'L' to last visible line on the screen

2.7. Telling where you are with CTRL-G

2.7.1. CTRL-G displays a status bar with info When it says 'col 2-9' it means you are at the second char and the 9th column of the screen (the first char, being a tab, eats up 8 columns)

2.7.2. :set number will display the current line number :set nonumber to switch it off

2.7.3. :set ruler to display the cursor position in the lower right corner

2.8. Scrolling around with CTRL-U/CTRL-D, CTRL-E/CTRL-Y, CTRL-F/CTRL-B

2.8.1. CTRL-U/CTRL-D scrolls by half screen

2.8.2. CTRL-E/CTRL-Y scrolls by a single line

2.8.3. CTRL-F/CTRL-B scrolls be entire screen except for two lines

2.9. Scrolling around with `zz', `zt' and `zb'

2.9.1. zz puts the current line in the middle of the screen

2.9.2. zt puts the current line at the top

2.9.3. zb putts the current line at the bottom

2.10. Searches with `/pattern' and `?pattern'

2.10.1. /pattern finds the next occurence of `pattern' after the cursor

2.10.2. ?pattern finds the previous occurence of `pattern'

2.10.3. when you type `/' `?' the focus goes to the bottom of the screen, there you can use <BS> and <Left>/<Right> to edit the pattern You can type <Up> and <Down> to travel through the history of past searchs The `:' commands also have a similar history

2.10.4. .*[]^%/\?~ and $ have special meaning (you might have to backslah them)

2.10.5. `n' repears the last search `N' repeats the last search in the opposite direction You can also put a count for those (3n or 3N), but you can't put a count on a search command

2.10.6. :set ignorecase to make searches case insensitive

2.10.7. '*' searches for the word under cursor `#' does the same in the opposite direction

2.10.8. \< and /> are end of words markers `the\>' is a pattern that looks for words that end in `the' `\<exact\>' matches the exact word `exact' (not `exactitude')

2.10.9. :set hlsearch to highlight search results :set nohlsearch to turn highlighting off :nohlsearch disable last search's highlighting (does not disable highlighting future searches)

2.10.10. :set incsearch for incremental searches

2.10.11. :set nowrapscan to stop search `wrapping'

2.11. Jumping around with `` (two-backquotes) and CTRL-O/CTRL-I

2.11.1. Most commands that can move you more than one line away are considered `jumps' (j and k are not)

2.11.2. ``(two-backquote) jumps back to previous position before the jump `(backquote) is a jump itself so typing it twice will get you back again

2.11.3. CTRL-O jumps to an Older position in the `jump' history O is for "Older position"

2.11.4. CTRL-I jumps to a newer position in the `jump' history CTRL-I is the same as <Tab> I is just next to O on the keyboard

2.11.5. :jumps gives a list of positions you jumped to

2.12. Putting marks with `(backquote)

2.12.1. `ma' creates a mark at the current position named a You can have up to 26 marks (a.. z)

2.12.2. 'mark moves to the beginning of the line containing the mark

2.12.3. `mark moves to the exact column of the mark

2.12.4. :marks gives a list of marks

2.12.5. Special marks ' the cursor position before the jump " The cursor position when last editing the file [ Start of the last change ] End of the last change

3. 3- Making Small Changes

3.1. operation-command followed by motion-command

3.1.1. `d' deletes and `w' moves by word, so `dw' deletes a word

3.1.2. Whether the character where the cursor ends up is included (inclusive command) or not (exclusive command) depends on the actual move command. `dw' does not delete the first character of the next word `de' does delete the last character of the word

3.2. `c' works like `d', but it leaves you in insert mode

3.2.1. `c2w' deletes two words and leaves you in insert mode

3.2.2. EXCEPTION: `cw' actually acts like `ce' and does not delete the space after the word

3.3. cc changes a whole line and keeps the indent

3.4. dd deletes a whole line

3.5. Single letter shortcuts

3.5.1. x stands for dl (delete character under cursor) Notice that it is d+l (move right)

3.5.2. X stands for dh (deletes character left of the cursor) Notice that it is d+h (move left)

3.5.3. D stands for d$ (deletes to the end of the line (inclusive))

3.5.4. C stands for c$ (changes to the end of the line)

3.5.5. S stands for cc (changes a whole line)

3.6. Put counts before the operation-command too

3.6.1. 3dw ``deletes a word'' three times

3.6.2. d3w deletes three words once

3.7. Replace a single character with `r'

3.7.1. `r' is NOT an operator

3.7.2. It waits for you to type in a character to replace the current one

3.7.3. You can use a count to replace ``that many characters'' 5rx (replaces with 5 x)

3.8. Repeating a change with `.'

3.8.1. E.g you want to delete all the <b> tags f< takes you to the first < df> deletes until the > f< takes you to the next one "." applies last change (df>) again etc

3.8.2. Repeats all changes except `u' CTRL-R and the : (colon) commands

3.8.3. E.g you want to change all occurrences of four to five /four searches for four cwfive<ESC> turns it to five `n' takes to the next occurrence `.' applies `cwfive<Esc>' again etc..

3.9. Start visual mode with `v'

3.9.1. Highlight the text you want and then trigger the desired operator (e.g d)

3.9.2. 'V' gets you into line-visual mode (easier to select lines)

3.9.3. CTRL-V for block mode

3.9.4. `o' goes to the other end of the selection

3.9.5. `O' goes to the other corner in the same line for block mode

3.10. Moving text with `p' and `P'

3.10.1. When you delete text with x or d, it is saved and you can recall it where you want

3.10.2. When you delete an entie line, `p' will put it back just under the cursor

3.10.3. When you delete parts of a line, `p' will put it back just after the cursor

3.10.4. `P' is the same except that it puts the text just before the cursor

3.10.5. You can put as many times as you like, the same text will be used

3.11. Copying text with `y'

3.11.1. `y' yanks text into a register so that you can get it back with p E.g y2w yanks two words including last space E.g y2e yanks two words excluding last space

3.11.2. yy yanks the whole line

3.11.3. To copy from the clipboard use the menu or prepend `"*' (double-quote star) to `p' and `y'

3.12. Use <operator-command> followed by <text-object>

3.12.1. Unlike motion commands, text objects do not depend on the current pos of the cursor in the object

3.12.2. Text objects apply to the object _around_ the cursor

3.12.3. `aw' a word daw deletes a word

3.12.4. `is' sentence without white space after it The works even if the sentence spans multiple lines

3.12.5. `as' sentence plus whitespace after it

3.12.6. You can also use text objects while in visual mode typing `as' in visual mode will select the whole sentence

3.13. Enter ``replace mode'' with R

3.13.1. In this mode all characters you type replace the ones under the cursor

3.14. Use `~' to change the case and move to the next char

3.14.1. This is not an operator (you can't combine it with motions)

3.14.2. 'tildeop' turns it into an operator

3.14.3. This does work in visual mode to change all selected characters

4. 4- Set Your Settings