Home ..

Basic commands for /bin/vi

Not intended to be a comprehensive list. At your local UNIX prompt type man vi for more commands.

Save/Quit Search Edit Notes

ENTER/RETURN
needed?
Key combinationResult
No ESC Stop the current command and prepare for the next command. Recommending using 'CTRL [' instead of ESC
Using this key combination multiple is OK; ignore any beeps that may sound.
No CTRL [ The same as ESC; used when ESC will not work (which can be often).
Moving around
No CTRL g Display current filename and 'line X of Y'
No SHIFT G Go directly to the bottom of the file (EOF).
No h Move the cursor LEFT 1 character; used when the LEFT Arrow key fails.
No j Move the cursor DOWN 1 character; used when the DOWN Arrow key fails.
No k Move the cursor  UP  1 character; used when the UP Arrow key fails.
No l Move the cursor RIGHT 1 character; used when the RIGHT Arrow key fails.
Yes :1 Go to line number 1, the beginning of the file.
Yes :number Go to line number number.
No SHIFT 6 Move the cursor to the beginning of the line
No SHIFT 4 Move the cursor to the end of the line
No b Move the cursor to the beginning current word
No B Move the cursor to the beginning current blank-delimited word
No e Move the cursor to the end current word
No E Move the cursor to the end current blank-delimited word
No CTRL D Move the cursor DOWN 1 page
No CTRL U Move the cursor UP 1 page
Saving and Quitting
Yes :w Write out (Save) the current file. Recommend using :w! instead.
Yes :wq same as :w, but the 'q' means quit. Recommend using :wq! instead.
Yes :w! Force write out; used when :w fails. This may still fail however.
Yes :wq! same as :wq!, but the with force; If the write fails, vi will still exit.
Yes :q Quit without saving. Recommend using :q! instead.
Yes :q! Force quite without saving. Should never fail.
Searching
Yes :/word Do a case-sensitive forward search for word
Yes :?word Do a case-sensitive backward search for word
Yes :s/word/text/g Substitute case-sensitive word with text. 'g' means globally (all instances in that line), otherwise just once.
Yes :1,$s/word/text/g Starting with line 1 until EOF, substitute case-sensitive word with text. 'g' means globally (all instances in that line), otherwise just once.
Yes :1,10s/word/text/g Starting with line 1 until line 10, substitute case-sensitive word with text. 'g' means globally (all instances in that line), otherwise just once.
Yes :,$s/word/text/g Starting with the current line until EOF, substitute case-sensitive word with text. 'g' means globally (all instances in that line), otherwise just once.
Editing
No u Undo last change. Older vi editors only remember 1 change!
No i Begin insert mode. Use 'CTRL [' to stop
No o (not zero) Insert new blank line below current line and stay insert mode on that line. Use 'CTRL [' to stop
No SHIFT o (not zero) Insert new blank line above current line and stay insert mode on that line. Use 'CTRL [' to stop
No yy Yank (copy) the current line. Stored in memory for use with 'p'
No numberyy Yank (copy) the next number lines. Stored in memory for use with 'p'
No p Paste deleted or yanked data. Use caution with numberyy
No yyp Yank the current line and immediately paste it. Duplicate line.
No r Replace the current character with next character typed in
No R Replace mode. Every existing character that is right of the cursor will be overwritten. Use 'CTRL [' to stop
No cw Change current word. Use 'CTRL [' to stop.
No c$ Change characters until end of line. Use 'CTRL [' to stop.
No x Delete current character. Stored in memory for use with 'p'
No numberx Delete current number characters. Stored in memory for use with 'p'
No dw Delete current word. Stored in memory for use with 'p'
No numberdw Delete current number words. Stored in memory for use with 'p'
No dd Delete current line. Stored in memory for use with 'p'
No numberdd Delete number lines. Stored in memory for use with 'p'
No d$ Delete every character until end of line.
No dG (SHIFT G). Delete every character until end of file.
No a Append. Some vi editors will append to end of word, other append to end of line.
No SHIFT j Join the next line with the current line.
No . Repeat last command

NOTES




Example text (pretend the cursor is on the letter j):

The quick brown fox jumped over the lazy dog.


Key combination Resulting text
isuddenly The quick brown fox suddenly jumped over the lazy dog. Inserted new text
yyp The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
Copied the existing line
rb The quick brown fox bumped over the lazy dog. Replaced j with b
Rslumped The quick brown fox slumped ver the lazy dog. Notice the cursor is still overwriting characters, not inserting.
cwslumped The quick brown fox slumped over the lazy dog. Like a 'R' replace followed by an 'i' insert.
c$fell asleep. The quick brown fox fell asleep. No more jumping.



Wednesday, 23-Jul-2008 15:52:46 EDT