Create your own awesome maps

Even on the go

with our free apps for iPhone, iPad and Android

Get Started

Already have an account?
Log In

VIM by Mind Map: VIM
0.0 stars - 0 reviews range from 0 to 5

VIM

1- Basic Editing

Insert Mode vs Normal Mode

In Normal mode the keystrokes are commands

To go to instert mode type i

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

Moving around using hjkl

the keys are on the home row of your right hand

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

Delete character with x

Delete line with dd

Join two lines with J

Undo the ``last edit'' with u

Redo the last undo with CTRL-R

Undos all the changes on the last edited line with U

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

Append with `a'

Same as i but puts you just after the character

Open a new line with `o'

Add a count before commands to increase their effects

3k moves you three lines down

3ahello<Esc> appends three times hello

The count always comes before the command it modifies

Write and exit with ZZ

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

Find help with :help

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

: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

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

2- Moving Around

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

`$' to the end of the line

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

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

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

`33G' takes you to line 33

`G' takes you to the last line

`gg' takes you to the first line

Matching parenthesis with `%'

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

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

Define what constitutes a parenthesis with the option `matchpairs'

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

`fx' moves to the next x in the line

`Fx' moved to the previous x in the line

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

These commands never cross lines

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

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

Moving aournd words with w/b and e/ge

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

Previous word start `b', Moves to the previous word start

Next word end `e'

Previous word end `ge'

These commands will move you across lines

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

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

'H' to first visible line on the screen

'M' to middle of the screen

'L' to last visible line on the screen

Telling where you are with CTRL-G

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)

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

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

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

CTRL-U/CTRL-D scrolls by half screen

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

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

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

zz puts the current line in the middle of the screen

zt puts the current line at the top

zb putts the current line at the bottom

Searches with `/pattern' and `?pattern'

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

?pattern finds the previous occurence of `pattern'

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

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

`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

:set ignorecase to make searches case insensitive

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

\< 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')

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

:set incsearch for incremental searches

:set nowrapscan to stop search `wrapping'

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

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

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

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

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

:jumps gives a list of positions you jumped to

Putting marks with `(backquote)

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

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

`mark moves to the exact column of the mark

:marks gives a list of marks

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- Making Small Changes

operation-command followed by motion-command

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

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

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

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

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

cc changes a whole line and keeps the indent

dd deletes a whole line

Single letter shortcuts

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

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

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

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

S stands for cc (changes a whole line)

Put counts before the operation-command too

3dw ``deletes a word'' three times

d3w deletes three words once

Replace a single character with `r'

`r' is NOT an operator

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

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

Repeating a change with `.'

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

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

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..

Start visual mode with `v'

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

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

CTRL-V for block mode

`o' goes to the other end of the selection

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

Moving text with `p' and `P'

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

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

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

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

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

Copying text with `y'

`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

yy yanks the whole line

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

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

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

Text objects apply to the object _around_ the cursor

`aw' a word, daw deletes a word

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

`as' sentence plus whitespace after it

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

Enter ``replace mode'' with R

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

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

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

'tildeop' turns it into an operator

This does work in visual mode to change all selected characters

4- Set Your Settings