Skip to content

Instantly share code, notes, and snippets.

@JakubTesarek
Last active August 12, 2018 17:57
Show Gist options
  • Save JakubTesarek/cec2451690b26e789b670499876ec4fa to your computer and use it in GitHub Desktop.
Save JakubTesarek/cec2451690b26e789b670499876ec4fa to your computer and use it in GitHub Desktop.
Vim cheatsheet

Navigation

Command Description
h Left
j Down
k Up
l Right

Moves

Command Description
w Word
b Beginning of previous word
B End of previous word
$ End of line
t Tag
/ ' Quotes
p Paragraph
s Sentence
e End of current word
w Beginning of next word
0 Beginning of line
% Matching bracket
( / [ / { Bracket

Modifiers

Command Description
i Inner
a Around

Navigation - File

Command Description
<C-g> Show position in file
:{num} / {num}G / {num}gg Goto line {num}
<C-e> Scroll down
<C-y> Scroll up
gg Beginning of file
G End of file
zz Center view around cursor

Modes

Command Description
<Esc> / <C-[> Normal mode
v Visual mode
V Line-wise visual mode
<C-v> Block-wise visual mode
gv Reselect last visual selection
i Insert mode
I Insert mode at the beginning of line
a Insert mode after cursor
A Insert mode at the end of line
s Delete character and insert mode
S / cc Delete line and insert mode
R Replace mode
C Change until end of line
c{move} Delete move and insert mode
r Change one character

Modifications

Command Description
x Delete character
o Open line
O Open line above
d Delete
D Delete until end of line
> Indent from cursor down
< Outdent from cursor down
>> Indent line
<< Outdent line
= Autoindent

History

Command Description
. Repeat
u Undo
U Undo whole line
<C-r> Redo

Clipboard

Command Description
"{reg}p Paste from {register}
"{reg}y{move} Yank {move} to {register}
"{reg}yy Yank line to {register}

Searching

Command Description
n Next search
N Previous search
/{term} Search {term}
?{term} Search {term} backwardsnn
\* Search for a word under cursor
# Search for a word under cursor backwards
:set ic Ignore case
<C-o> Return to last possition
f{char} Find {char}
F{char} Find {char} backwards
t{char} Find {char}, skip before
T{char} Find {char} backwards, skip before
/\<{word}\> Search for whole word
q/ Open search history

Replace

Command Description
:s/{orig}/{new} Substitute
:{start}, {end}s/{orig}/{new}/g Substitute globally on lines from start to end
%s/{orig}/{new}/gc Substitute globally in whole file with confirm
:s//{new} Replace last seareched term with new

Help

Command Description
:h[elp] {topic} Search help
:h[elp] i_CTRL-{commnad) Help for command
<C-d> Show available commands

Visual Mode

Command Description
o Get to the other end of selected text

Insert mode

Command Description
<C-o> One command in insert mode
<C-u> Delete line
<C-w> Delete word
<C-h> Backspace
<C-r>{num} Paste from register {num}
<C-r>= Insert from expression register
<C-v>{code} / <C-v>u{code} Insert (unicode) character by numeric code
<C-k>{char}{char} Inser character by digraph

Normal mode

Command Description
{num=1}<C-a> Increment next number by num
{num=1}<C-x> Decrement next number by num
gU Uppercase
g~ Switch case
gu Lowercase
! Filter lines throught external program
ga Display numeric value of character

Ex mode

Command Description
:q[uit]! Quit without saving
:w[rite] Write
@: Run last command again
@@ Repeat last repeat
:!{command} Execute external command
:r {file} Insert content of file
:r !{command} Insert output of command
:set tw={num} Set line width
:set wrap / :set nowrap Set line wrap
:nohl Hide higlight
:set cursorline Underline active line
:{range}p Print {range}
:{range}d Delete {range}
:co[py] / :t Copy
:m[ove] Move
:normal Make normal command
<C-r><C-w> Insert word under cursor to command line
q: Command line window
:shell Open shell
exit Exit shell
:read !{cmd} Output command to under cursor
:qa Quit all
:wa Write all

Range modifiers

Command Description
. Current line
% Whole file
$ End of file
/{pattern}/ Line matching pattern
{address}+{num} Num lines after address
'< Start of visual selection
'> End of visual selection
0 First virtual line
'{mark} Mark

Buffers

Command Description
:ls Show all buffers
:bnext / <C-^> Next buffer
:bprev Previous buffer
:bfirst First buffer
:blast Last buffer
:b[uffer] {num} Buffer {num}
:b[uffer] {name} Buffer with file containing {name}
:bufdo Execute command on all files in buffer
:argdo Execute command on all files in arguments
:args Display all args
:next Next arg
:prev[ious] Previous arg
:lcd Change pwd
:windo Execute commnad on all windows
:pwd Current working directory

Windows

Command Description
<C-w>s Horizontal window split
<C-w>v Vertical window split
:e[dit] {file} Edit {file} in current window
:sp[lit] {file} Horizontal split and edit {file}
:vs[plit] {file} Vertical split and edit {file}
<C-w>w Cycle between windows
<C-w>{direction: hjkl} Focus to window in {direction}
<C-w>c / :clo[se] Close active window
<C-w>c / :on[ly] Close all inactive windows
<C-w>= Equalize size of all windows
<C-w>_ Maximaze height of current window
<C-w> Maximaze width of current window
<C-w>T Open current window in new tab

Tabs

Command Description
:tabe[dit] {path} Open {path} in tab
:tabo[nly] Close all other tabs
:tab {commnand} Open {command} in tab instead of split screen
:tabs Show all tabs
:tabn[ext] {num} / {num}gt Switch to tab {num} or next
:tabp[revious] / gT Previous tab
{num}gt Tab number {num}
:tabc[lose] Close tab and all its windows
:tabmove {num} Move current tab to {num} possition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment