76 Shortcuts for Vim

1. Cursor Movement

hMove left
jMove down
kMove up
lMove right
wJump by start of words
WJump by words
eJump to end of words
EJump to end of words (no punctuation)
bJump backward by words (punctuation considered words)
BJump backward by words (no punctuation)
0Start of line
^First non-blank character of line
$End of line
GGo To command (prefix with number)
iStart insert mode at cursor
IInsert at the beginning of the line
aAppend after the cursor
AAppend at the end of the line
oOpen (append) blank line below current line (no need to press return)
OOpen blank line above current line
eaAppend at end word
EscExit insert mode

2. Editing

rReplace a single character (does not use insert mode)
JJoin line below to the current one
ccChange (replace) an entire line
cwChange (replace) to the end of word
c$Change (replace) to the end of line
sDelete character at cursor and subsitute text
SDelete line at cursor and substitute text (same as cc)
xpTranspose two letters (delete and paste, technically)
uUndo
.Repeat last command

3. Making text (Visual mode)

vStart visual mode, mark lines, then do command (such as y-yank)
VStart Linewise visual mode
oMove to other end of marked area
Ctrl+vStart visual block mode
OMove to other corner of block
awMark a word
abA () block (with braces)
aBA {} block (with brackets)
ibInner () block
iBInner {} block
EscExit visual mode

4. Visual commands

>Shift right
<Shift left
yyank (copy)marked text
dDelete marked text
~Switch case

5. Cut and Paste

yyYank (copy) a line
2yyYank 2 lines
ywYank word
y$Yank to end of line
pPut (paste) the clipboard after cursor
PPut (paste) before cursor
ddDelete (cut) a line
dwDelete (cut) the current word
xDelete (cut) current character

6. Exiting

:wWrite (save) the file, but don’t exit
:wqWrite (save) and quit
:qQuit (fails if anything has changed)
:q!Quit and throw away changes

7. Search/Replace

/patternSearch for pattern
?pattenSearch backward for pattern
nRepeat search in same direction
NRepeat search in opposite direction
:%s/old/new/gReplace all old with new throughout file
:%s/old/new/gcReplace all old with new throughout file with confirmations

8. Working with multiple files

:e filenameEdit a file in a new buffer
:bnextGo to next buffer
:bprevGo to previous buffer
:bdDelete a buffer (close a file)
:sp filenameOpen a file in a new buffer and split window
Ctrl+wsSplit windows
Ctrl+wwSwitch between windows
Ctrl+wqQuit a window
Ctrl+wvSplit windows vertically

Leave a Reply

Your email address will not be published. Required fields are marked *