Useful VI Commands

· Avaya
Authors

To Start
vi filename     edit filename starting at line 1
vi -r filename     recover filename that was being edited when system crashed

To Exit
:x<Return>     quit vi, writing out modified file to file named in original invocation
:wq<Return>     quit vi, writing out modified file to file named in original invocation
:q<Return>     quit (or exit) vi
:q!<Return>     quit vi even though latest changes have not been saved for this vi call

Add & Insert
i     insert text before cursor, until <Esc> hit
I     insert text at beginning of current line, until <Esc> hit
a     append text after cursor, until <Esc> hit
A     append text to end of current line, until <Esc> hit
o     open and put text in a new line below current line, until <Esc> hit
O     open and put text in a new line above current line, until <Esc> hit

Delete
x     delete single character under cursor
Nx     delete N characters, starting with character under cursor
dw     delete the single word beginning with character under cursor
dNw     delete N words beginning with character under cursor;
e.g., d5w deletes 5 words
D     delete the remainder of the line, starting with current cursor position
dd     delete entire current line
Ndd or dNd     delete N lines, beginning with the current line;
e.g., 5dd deletes 5 lines

Copy & Paste
yy     copy (yank, cut) the current line into the buffer
Nyy or yNy     copy (yank, cut) the next N lines, including the current line, into the buffer
p     put (paste) the line(s) in the buffer into the text after the current line

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: