Published on

Vim Cheatsheet

Authors

Scroll to the bottom for the "basics." Section in the middle is for commands that I thought were helpful in vim terminal but never use in VS Code.

My favorites

Editing & Deleting Text

ShortcutSummaryDescription
yyYank lineCopy the current line
ddDelete lineDelete the current line
pPaste afterPaste after the cursor
PPaste beforePaste before the cursor
xDelete charDelete character under the cursor
diwDelete inner wordDelete word under the cursor
dwDelete wordDelete from cursor to end of word
dawDelete a wordDelete from cursor to end of word and space after

Advanced Editing Commands

ShortcutSummaryDescription
yYankCopy selection
dDeleteDelete selection
ccChange lineChange the entire current line
cwChange wordChange from the cursor to end of the word
ciwChange inner wordChange the word under the cursor
sSubstitute charDelete char under cursor & enter Insert mode

Modes & Selection

ShortcutSummaryDescription
iInsert modeEnter insert mode before the cursor
aAppend modeEnter insert mode after the cursor
oOpen belowOpen a new line below and enter insert mode
OOpen aboveOpen a new line above and enter insert mode
vVisual selectEnter visual mode for character selection
VVisual lineEnter visual mode for line selection

Search & Navigation

ShortcutSummaryDescription
fFind char in lineFind next occurrence of character in line
FFind char backward in lineFind previous occurrence of character in line
/SearchSearch for a pattern in the file
nNext matchJump to the next match
NPrevious matchJump to the previous match
ctrl+uUp half-screenMove up half a screen
ctrl+dDown half-screenMove down half a screen
ctrl+bBack one screenMove back one full screen

Text Replacement & Repeat

ShortcutSummaryDescription
rReplace charReplace character under the cursor
:s/foo/bar/gReplaceReplace 'foo' with 'bar' in the current line
:%s/foo/bar/gReplace allReplace 'foo' with 'bar' in the entire file
.RepeatRepeat the last command

Settings & Display

ShortcutSummaryDescription
JJoin linesJoin the current line with the next one
>>Indent lineIndent current line one level to the right
<<Unindent lineUnindent current line one level to the left

Remaining Editing Commands

ShortcutSummaryDescription
uUndoUndo the last change
<C-r>RedoRedo the last undone change
SSubstitute lineDelete line and enter Insert mode
~Change caseToggle case of the character under the cursor
<C-v>Block visualEnter visual block mode

Stuff I don't really use in VS Code now

File Operations & Window Management

ShortcutSummaryDescription
:wSaveSave the current file
:qQuitQuit Vim (requires no unsaved changes)
:eOpen fileEdit a file in a new buffer
:tabnewNew tabOpen a file in a new tab
:spSplit windowSplit the window horizontally
:vspVertical splitSplit the window vertically

Buffer Management

ShortcutSummaryDescription
:bnNext bufferGo to the next buffer
:bpPrevious bufferGo to the previous buffer
:bdClose bufferClose the current buffer
ctrl+wwSwitch windowsSwitch between windows
:wqSave & QuitSave changes and quit Vim
:q!Force quitQuit Vim without saving changes

Settings & Display

ShortcutSummaryDescription
:set nuShow line numbersDisplay line numbers
:set nonuHide line numbersHide line numbers
:nohRemove highlightRemove search highlighting until next search

The Basics

Basic Cursor Movement

ShortcutSummaryDescription
hLeftMove one character to the left
lRightMove one character to the right
jDownMove one line down
kUpMove one line up
0Line startMove to the start of the line
$Line endMove to the end of the line

Word & Paragraph Navigation

ShortcutSummaryDescription
wNext wordMove to the start of the next word
bPrevious wordMove to the start of the previous word
^First non-blankMove to the first non-blank character of the line
ggTop of fileMove to the top of the file
GBottom of fileMove to the bottom of the file
}Next paragraphMove to the beginning of the next paragraph
{Previous paragraphMove to the beginning of the previous paragraph