Movement (in command mode)
| k |
Move Up (also <up arrow>) |
| j |
Move Down (also <down arrow> <enter>) |
| l |
Move Left (also <left arrow>, <bkspace>) |
| h |
Move Right (also <right arrow>, <spacebar>) |
| $ |
Jump to end of current line |
| 0 |
Jump to beginning of current line |
| w |
Jump to beginning of next word (space or metacharacter. ie semicolon) |
| W |
Jump to beginning of next Word (space) |
| b |
Jump to beginning of this (or previous) word |
| B |
Jump to beginning of previous Word |
| [[ |
Jump to top of section (default: top of document) |
| ]] |
Jump to bottom of section (default: bottom of document) |
| H |
Jump to top of screen ('4H' will Jump to 4 lines below top of screen) |
| L |
Jump to bottom of screen ('4L' will Jump to 4 lines above bottom of screen) |
| G |
Goto EOF ('4G' will Goto Line 4) |
|
Note: in any of the 'Jump to' commands, a number can be entered to specify more than one.
ie 'w' will jump ahead 1 word, while '6w' will jump ahead 6 words. |
Editing
| x |
delete character under cursor and return to command mode |
| X |
delete character before cursor and return to command mode |
| r |
replace character under cursor and return to command mode |
| R |
overwrite characters (until <esc> is pressed) |
| s |
substitute characters, then insert. Usually used with a number (ie '4s' overwrites the next 4 characters, then inserts any additional characters typed). |
| d_ |
delete. This can be used in conjunction with any of the "Jump to" commands from the Movement section.
In addition, number values can be included (ie 'd4w' will delete the next 4 words).
'dd' will delete current line. |
| y_ |
yank. Used in the same manner as 'd_' |
| p |
paste. |
| u |
undo last set of commands |
| U |
undo last editing on current line only (unless you move off the line you were editing) |
| . |
repeat last command. |
Other Commands (in command mode)
| :q |
quit |
| :q! |
quit without saving changes. |
| :w |
write. ':w foo.txt' will specify write to the file 'foo.txt' -- default is current file. |
| :wq |
write, then quit. Can also be done with 'ZZ' |
| :!_ |
execute command line command. ie ':!pwd' will suspend vi and execute the 'pwd' command from the command line |
| /_ |
search in document for string '_' (case matters) |
| n |
find next (used in conjunction with the '/' command) |
| N |
find previous |
| :g/foo/s//bar/g |
globally replace any occurance of the string 'foo' in the document with the string 'bar' |
:%s/<ctrl-v><enter>//g
:g/<ctrl-v><enter>///g |
remove the pesky ^M from the end of lines
|