Show Menu

Comprehensive VIM Cheat Sheet by typo209

Comprehensive VIM Cheat Sheet information sourced from: http://www.tuxfiles.org/linuxhelp/vimcheat.html

Working With Files

:e filenameOpen a new file. You can use the Tab key for automatic file name comple­tion, just like at the shell command prompt.
:w filenameSave changes to a file. If you don't specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:qQuit Vim. If you have unsaved changes, Vim refuses to exit.
:q!Exit Vim without saving changes.
:wqWrite the file and exit.
:xAlmost the same as :wq, write the file and exit if you've made changes to the file. If you haven't made any changes to the file, Vim exits without writing the file.

Moving Around in the File

j or UpMove the cursor up one line.
k or DownDown one line.
h or LeftLeft one character.
l or RightRight one character.
eTo the end of a word.
ETo the end of a whites­pac­e-d­eli­mited word.
bTo the beginning of a word.
BTo the beginning of a whites­pac­e-d­eli­mited word.
0To the beginning of a line.
^To the first non-wh­ite­space character of a line.
$To the end of a line.
HTo the first line of the screen.
MTo the middle line of the screen.
LTo the the last line of the screen.
:nJump to line number n. For example, to jump to line 42, you'd type :42
 

Editing Blocks of Text

~Change the case of charac­ters. This works both in visual and command mode. In visual mode, change the case of highli­ghted charac­ters. In command mode, change the case of the character uder cursor.
> (V)Shift right (indent).
< (V)Shift left (de-in­dent).
c (V)Change the highli­ghted text.
y (V)Yank the highli­ghted text. In Windows terms, "copy the selected text to clipbo­ard."
d (V)Delete the highli­ghted text. In Windows terms, "cut the selected text to clipbo­ard."
yy or :y or YYank the current line. You don't need to highlight it first.
dd or :dDelete the current line. Again, you don't need to highlight it first.
pPut the text you yanked or deleted. In Windows terms, "­paste the contents of the clipbo­ard­". Put characters after the cursor. Put lines below the current line.
PPut characters before the cursor. Put lines above the current line.

Note: the Vim commands marked with (V) work in visual mode, when you've selected some text. The other commands work in the command mode, when you haven't selected any text.

Deleting Text

xDelete characters under the cursor.
XDelete characters before the cursor.
dd or :dDelete the current line.
 

Inserting and Overwriting Text

iInsert before cursor.
lInsert to the start of the current line.
aAppend after cursor.
AAppend to the end of the current line.
oOpen a new line below and insert.
OOpen a new line above and insert.
CChange the rest of the current line.
rOverwrite one character. After overwr­iting the single character, go back to command mode.
REnter insert mode but replace characters rather than inserting.
ESCExit insert­/ov­erwrite mode and go back to command mode.

Search

/patternSearch the file for pattern.
nScan for next search match in the same direction.
NScan for next search match but opposite direction.

Undo and Redo

uUndo the last action.
UUndo all the latest changes that were made to the current line.
Ctrl+rRedo.

Visual Mode

vStart highli­ghting charac­ters. Use the normal movement keys and commands to select text for highli­ghting.
VStart highli­ghting lines.
ESCExit visual mode and return to command mode.
 

Share This Cheat Sheet!

Favourited by 8 Members:

wigust claysmith gmickd Eric Normandeau Sibicle ninetails akipta hoornet

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.