[an error occurred while processing this directive]
Note: when invoking vi, execute a "vi filename" from the UNIX shell prompt. All commands are then seperated by a pressing of the <escape> key.
Command: | Meaning: |
a | Append text after cursor |
A | Append text at line's end |
i | Insert text before the cursor |
I | Insert text at the beginning of the line |
o | Open a new line, below the cursor |
O | Open a new line above the cursor |
h | Move left one character |
j | Move down one line |
k | Move up one line |
l | Move right (forward) one character |
w | Move right (forward) one word |
W | Move right one word (past punctuation) |
b | Move left (backward) one word |
B | Move left (backward) one word (past punctuation) |
e | Move to end of the current word |
<Return> | Move down one line |
H | Move to top of screen |
M | Move to middle of screen |
L | Move to bottom of the screen |
G | Go to the end of the file (last line) |
1G | Go to the first line of the file |
21G | Go to line 21 |
nG | Go to line 'n' |
<Control>-f | Page forward one screen |
<Control>-d | Scroll down one half screen |
<Control>-b | Page back one screen |
<Control>-u | Scroll up one half screen |
x | Delete the character at the cursor |
X | Delete character to the left of the cursor |
dw | Delete the word to the right of the cursor |
dd | Delete the whole line that the cursor is on |
D | Delete from the cursor to the end of the current line |
dG | Delete from the cursor to the end of the file |
d1G | Delete from the beginning of the file to the cursor |
:5,10d | Delete lines 5 through 10 |
cw | Change (replace) word at the cursor location |
cw# | Change (replace) the number of words indicated by '#' |
R | Change (replace) line |
C | Change from cursor to the end of the line |
s | Substitute string of characters from cursor forward |
r | Replace character at cursor with another character |
r <Return>
i <Return> |
Break line |
J | Join current line and line below |
xp | Transpose character at cursor and character to the right |
~ | Change case of letter (upper or lower) |
u | Undo previous command |
U | Undo all changes to current line |
:u | Undo previous changes to last line command |
yy | Yank (copy) the current line |
Y | Yank (copy) the current line |
p | Put yanked (or deleted) line below the current line |
P | Put yanked (or deleted) line above the current line |
:1,3 co 5 | Copy lines 1 through 3 and put them below line 5 |
:4,6 m 8 | Move lines 4 through 6 to line 8. |
:w | Save changes (write to file) |
:w new_filename | Save as a new_filename |
:wq | Save and quit |
:wq! | Forced write (even on files with no write access) and quit (owner only). |
zz | Save changes and quit vi |
:q! | Quit without saving changes |
:! cmd | execute cmd |
:e file | edit file |
:n | next file; when editting multiple files |
:r file | read the contents of file into editor |
:r! cmd | read output of cmd into text |
:se | displays currently set options |
:se all | displays all available options |
:set nu | Show line numbers |
:set nonu | Hide line numbers |
:set ic | Searches should ignore case |
:set noic | Searches should be case sensitive |
:set list | Turn of the display of invisible characters |
:set showmode | Turn on input mode identification |
:set noshowmode | Turn off input mode identification |
<Control>-l | Clear (refresh) scrambled screen |
/string | Search forward for string |
?string | Search backward for string |
n | Find next occurence of string in search direction |
N | Find previous occurence of string in search direction |
:s/old/new/g | Search and replace in the current line |
:%s/old/new/g | Search and replace globally (whole file) |
Other vi reference pages can be found at:
http://www.wittys.com/vi.20030112.html
- Jason's vi page - text only
http://www.cis.udel.edu/~totten/vi/
http://www.hackensackhigh.org/viref.html
http://www.ungerhu.com/jxh/vi.html
http://www.kichwa.com/quik_ref/vi_ref.html