create
learn
share

Vim

edit

Summary

Memorize keyboard shortcuts for the Vim editor. Most apply to vi also.

Conventions

The ^ means hold down the ctrl key. For example, ^w means hold down ctrl and press w. Also, pressing Enter is necessary after commands that begin with ~:~ but this is omitted for brevity.

Basics

ActionType
start vimvim (command)
start vim tutorialvimtutor (command)
two "modes"normal mode and insert mode
go into insert modei (see below for others)
go into normal modeesc (or ^c or ^[)
cancel out of current command (or search, etc.)esc (or ^c or ^[)
start learning
start learning

Cursor Movement

Getting around the screen...

 

ActionKey
lefth
rightl
upk
downj
beginning of line0
end of line$
start learning
start learning

 

Note that the arrow keys also work for moving around. Also, feel free to use the mouse to move around and select (won't work in a terminal window).

Editing

Once you've enter edit mode (usually via i or A) and insert some text, you'll usually want to press esc (or ^c or ^[) so you can again use the movement-related commands.

 

ActionKey
insert texti
insert text at end of lineA (then start typing)
insert text after cursora
insert text in place of a wordcw (then start typing)
start learning
start learning

Saving and quitting, etc.

ActionKey
save file:w
exit (saving file)ZZ (or) :wq
exit (without saving file):q!
open myfile.txt (in current dir):e myfile.txt
browse current dir:e .
start learning
start learning

Misc

ActionKey
undou
redo^r
repeat (last action).
alternatives for escape^c or ^[
down 3 lines3j
go to line 33G
go back to previous "jump" locations^o
start learning
start learning

 

Note that typing numbers before commands usually means "repeat the command this many times" (as in 3 j).

Searching

ActionKey
search/
search (backward)?
do previous search (while searching)^p
do next search (while searching)^n
see previous searches (while searching)^f
go to next instance of a (on same line)fa
find next instance of word*
start learning
start learning

 

Incremental searching is a very cool feature. It means that the cursor will search forward as you type a search string (used with / search). Add "set incsearch" to your .vimrc file if incremental searching isn't enabled.

Movement II

ActionKey
right 1 wordw
left 1 wordb
right 1 word (to word end)e
page down^f
page up^b
beginning of line text^ (shift-6)
start learning
start learning

Movement III

ActionKey
beginning of filegg
end of fileG
jump to matching parenthesis%
backward or forward paragraph{ or }
backward or forward sentence( or )
start learning
start learning

Directories

ActionKey
view root dir
up one dir- (while viewing dir)
toggle dir display modei (while viewing dir)
create dird (while viewing dir)
rename file or dirR (while viewing dir)
start learning
start learning

Deleting

ActionKey
delete charx
delete linedd
delete worddw
insert last deletedP
delete until end of lined$
start learning
start learning

Pages

Vim 2- includes config settings
blog comments powered by Disqus