VIM Quick Reference Guide
The most important VIM commands
Press the <ESC> (escape) key to get to normal mode, then:
:q! quits without saving
:wq saves and quits (write quit)
x deletes individual characters
i inserts text
dw deletes to the end of a word (d2w deletes two words, d3w deletes three words, etc.)
d$ deletes to the end of a line
dd deletes an entire line (2dd deletes two lines, 23dd deletes 23 lines, etc.)
u undoes the last command
U fixes an entire line
<CTRL>R redoes the command
p puts the last deletion after the cursor
r replaces the character under the cursor
cw is the “change word” command, that deletes the word (from the cursor to the right) and places you in “insert” mode
c$ is the “change line” command, that deletes the line (from the cursor to the right) and places you in “insert” mode
<CTRL>g shows your location in a file
<SHIFT>G moves to the end of the file, [number]<SHIFT>G moves to the line number specified in the command, for example 1<SHIFT>G moves to line #1.
/[search term] searches forward through a file for the search term. For example, “/apache” will search for the next instance of the word “apache” in the file
?[search term] searches backwards through a file for the search term. For example, “?apache” will search for the last instance before the cursor of the word “apache” in the file
:s/[old]/[new] will replace the next instance of “old” with “new”. For example, :s/blue/red will replace the next instance of “blue” with “red”.
:s/[old]/[new]/g will replace the every instance of “old” on the current line with “new”. For example, :s/blue/red will replace the every instance of “blue” with “red”.
:#,#s/[old]/[new]/g will replace every instance of “old” with “new” in the range of lines specified with the # sign.
:! allows you to execute external commands
:set nu turns on line numbering
:nohlsearch turns off highlighting of search terms
Learn more about working with Linux systems in our Linux server training workshop. Click here for details
Click here for a free PDF of this guide, formatted to tape to the side of your monitor.
soundtraining.net
Accelerated, task-based training for IT pros
On the web: www.soundtraining.net
On the phone: (206) 988-5858
© 2010, soundtraining.net. Content may be reprinted and/or distributed as long as this document remains unaltered and soundtraining.net, any named author, and www.soundtraining.net are credited as the source.
