You are on page 1of 1

General Startup

To use vi: vi filename Deleting


To exit vi and save changes: ZZ or :wq x delete character under cursor
To exit vi without saving changes: :q! dd delete line under cursor
To enter vi command mode: [esc] dw delete word under cursor
Counts db delete word before cursor
A number preceding any vi command tells vi to repeat that
command that many times. Copying Code
yy (yank)'copies' line which may then be put by the
Cursor Movement p(put) command. Precede with a count for multiple lines.
h move left (backspace)
j move down Put Command
k move up brings back previous deletion or yank of lines, words, or
l move right (spacebar) characters
[return] move to the beginning of the next line P bring back before cursor
$ last column on the current line p bring back after cursor
0 move cursor to the first column on the current line
^ move cursor to first nonblank column on the current Find Commands
line ? finds a word going backwards
w move to the beginning of the next word or / finds a word going forwards
punctuation mark f finds a character on the line under the cursor
W move past the next space going forward
b move to the beginning of the previous word or F finds a character on the line under the cursor
punctuation mark going backwards
B move to the beginning of the previous word, ignores t find a character on the current line going forward
punctuation and stop one character before it
e end of next word or punctuation mark T find a character on the current line going backward
E end of next word, ignoring punctuation and stop one character before it
H move cursor to the top of the screen ; repeat last f, F, t, T
M move cursor to the middle of the screen
L move cursor to the bottom of the screen Miscellaneous Commands
. repeat last command
Screen Movement u undoes last command issued
G move to the last line in the file U undoes all commands on one line
xG move to line x xp deletes first character and inserts after second
z+ move current line to top of screen (swap)
z move current line to the middle of screen J join current line with the next line
z- move current line to the bottom of screen ^G display current line number
^F move forward one screen % if at one parenthesis, will jump to its mate
^B move backward one line mx mark current line with character x
^D move forward one half screen 'x find line marked with character x
^U move backward one half screen NOTE: Marks are internal and not written to the file.

Inserting WRITE FILE


r replace character under cursor with next character :w saves the current file without quitting
typed
R keep replacing character until [esc] is hit MOVING
i insert before cursor :# move to line #
a append after cursor :$ move to last line of file
A append at end of line
O open line above cursor and enter append mode

You might also like