Useful VI Commands

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

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

Sponsored Post Learn from the experts: Create a successful blog with our brand new courseThe Blog

Are you new to blogging, and do you want step-by-step guidance on how to publish and grow your blog? Learn more about our new Blogging for Beginners course and get 50% off through December 10th. is excited to announce our newest offering: a course just for beginning bloggers where you’ll learn everything you need to know about blogging from the most trusted experts in the industry. We have helped millions of blogs get up and running, we know what works, and we want you to to know everything we know. This course provides all the fundamental skills and inspiration you need to get your blog started, an interactive community forum, and content updated annually.