Friday, November 7, 2008

"Vi" Cheat sheet

Cursor movement:

h     Move cursor left
j      Move cursor down
k     Move cursor up
l     Move cursor right
ctrl-d     Scroll down one half of a page
ctrl-u     Scroll up one half of a page
ctrl-f     Scroll forward one page
ctrl-b     Scroll back one page
M     Move cursor to middle of page
H     Move cursor to top of page
L     Move cursor to bottom of page
w     Move cursor a word at a time
3w     Move cursor ahead 3 words
B     Move cursor back a word at a time
b     Move cursor back a word at a time
3b     Move cursor back 3 words
e     Move cursor to end of word
3e     Move cursor ahead to the end of the 3rd word
$     Move cursor to end of line
)     Move cursor to beginning of next sentence
(     Move cursor to beginning of current sentence
G     Move cursor to end of file

Editing commands:

i     Insert at cursor
a     Append after cursor
A     Append at end of line
ESC     Terminate insert mode
u     Undo last change
U     Undo all changes to entire line
o     Open a new line
dd     Delete line
3dd     Delete 3 lines.
D     Delete contents of line after cursor
C     Delete contents of line after cursor and insert new text. Press esc key to end insertion.
dw     Delete word
3dw     Delete 3 words
cw     Change word
x     Delete character at cursor
r     Replace character
R     Overwrite characters from cursor onward
s     Substitute one character under cursor continue to insert
S     Substitute entire line and begin to insert at beginning of line
~     Change case of individual character

/word     --press Enter Search for word
?word     --press Enter Search backwards for word
n     Find next occurrence of search_word
N     Find previous occurrence of search_word



Other commands:

ZZ     Save changes and quit.
:wq     Save (write) changes and quit.
:w     Save (write) changes without quitting.
:q!     Ignore changes and quit.