Useful Vim (vi) commands

Basic

[table]command, action
ESC, Leave edit mode and return to command mode
Cntl-F, Foreward (down) one page
Cntl-B, Back (up) one page
Cntl-L, Refresh page
G, Move cursor at the end of the file
1G or gg, Move cursor at the beginning of the file
$, Move cursor at the end of the line
0, (zero) Move cursor at the beginning of the line[/table]

Editing

[table]command, action
a, Insert text after the cursor [TEXT]
i, Insert text at the current cursor position [TEXT]
A, Insert text at the end of the line [TEXT]
I, Insert text at the beginning of the line [TEXT]
o, Add a line below the cursor [TEXT]
O, Add a line above the cursor [TEXT]
u, Undo the last change
:red, Redo the undone changes with ”u” or ”:u”
x, Remove a character (and automatically put in the vim-clipboard)
D, Remove the rest of the line (after the cursor)
dw, Remove a word (until the next white blank space)
dd, Remove the line
8x, Remove 8 characters
2dw, Remove 2 words
7dd, Remove 7 lines
p, Insert the content of the vim-clipboard after the current cursor
P, Insert the content of the vim-clipboard before the current cursor
s, Replace a character for text [TEXT]
15s, Replace 15 characters for text [TEXT]
r, Replace a single character for other one without enter in text editor mode
R, Overwrite [TEXT]
J, Join the line before and the current line
i[ENTER], Break a line in two
., Repeat the last change done
yy, Insert the current line in the vim-clipboard
5yy, Insert five lines in the vim-clipboard
:w, Save in the file the changes made
:wq, Save and exit
:q, Exit without save changes
:q!, Force exit without save changes
[/table]

Moving

[table]command, action
+, Go to the next line
-, Go to the previous line
:+8, Go 8 lines down
:-9, Go 9 lines up
:6, Go to line number 6
ma, Mark a line with the tag ‘a’. (Only can use one letter)
‘a, Go to the line with the tag ‘a”.

Searching

[table]command, action
/text/, Search from where there cursor is the word “text”.
?text?, Search backward the word “text”.
n, Continue searching in the chosen direction.
N, Continue searching in the opposite direction.
/i.ad/, Search iXad where X is any character
/i..ad/, Search iXXad where XX are two any characteres
:set ic, Case insensitive for search and replaces
:set noic, Case sensitive[/table]