Vim Cheat Sheet
Vim Cheat Sheet
diw - delete (cut) word under the cursor Ctrl + wH - make current window full height at far left (leftmost vertical window)
B - jump backwards to the start of a word . - repeat last command
(words can contain punctuation) Ctrl + wL - make current window full height at far right (rightmost vertical window)
daw - delete (cut) word under the cursor and
ge - jump backwards to the end of a word Marking text (visual mode) the space after or before it
Ctrl + wJ - make current window full width at the very bottom (bottommost
v - start visual mode, mark lines, then do a horizontal window)
gE - jump backwards to the end of a word command (like y-yank) :3,5d - delete lines starting from 3 to 5
(words can contain punctuation) Ctrl + wK - make current window full width at the very top (topmost horizontal
V - start linewise visual mode window)
% - move cursor to matching character :g/{pattern}/d - delete all lines
(default supported pairs: '()', '{}', '[]' - use :h o - move to other end of marked area containing pattern
Diff
matchpairs in vim for more info)
Ctrl + v - start visual block mode :g!/{pattern}/d - delete all lines not zf - manually define a fold up to motion
0 - jump to the start of the line containing pattern
O - move to other corner of block d$ or D - delete (cut) to the end of the line zd - delete fold under the cursor
^ - jump to the first non-blank character of
the line aw - mark a word x - delete (cut) character za - toggle fold under the cursor
$ - jump to the end of the line ab - a block with () zo - open fold under the cursor
Indent text
g_ - jump to the last non-blank character of aB - a block with {} >> - indent (move right) line one shiftwidth zc - close fold under the cursor
the line
at - a block with <> tags << - de-indent (move left) line one shiftwidth zr - reduce (open) all folds by one level
gg - go to the first line of the document
ib - inner block with () >% - indent a block with () or {} (cursor on zm - fold more (close) all folds by one level
G - go to the last line of the document brace)
iB - inner block with {} zi - toggle folding functionality
5gg or 5G - go to line 5 <% - de-indent a block with () or {} (cursor
it - inner block with <> tags on brace) ]c - jump to start of next change
gd - move to local declaration
Esc or Ctrl + c - exit visual mode >ib - indent inner block with () [c - jump to start of previous change
gD - move to global declaration
Visual commands >at - indent a block with <> tags do or :diffg[et] - obtain (get) difference (from other buffer)
fx - jump to next occurrence of character x
> - shift text right 3== - re-indent 3 lines dp or :diffpu[t] - put difference (to other buffer)
tx - jump to before next occurrence of
character x < - shift text left =% - re-indent a block with () or {} (cursor on :diffthis - make current window part of diff
brace)
Fx - jump to the previous occurrence of y - yank (copy) marked text :dif[fupdate] - update differences
character x =iB - re-indent inner block with {}
d - delete marked text :diffo[ff] - switch off diff mode for current window
Tx - jump to after previous occurrence of gg=G - re-indent entire buffer
character x ~ - switch case
]p - paste and adjust indent to current line
; - repeat previous f, t, F or T movement u - change marked text to lowercase
, - repeat previous f, t, F or T movement, U - change marked text to uppercase Exiting
backwards :w - write (save) the file, but don't exit
Registers
} - jump to next paragraph (or :w !sudo tee % - write out the current
function/block, when editing code) :reg[isters] - show registers content file using sudo
{ - jump to previous paragraph (or "xy - yank into register x :wq or :x or ZZ - write (save) and quit
function/block, when editing code)
"xp - paste contents of register x :q - quit (fails if there are unsaved changes)
zz - center cursor on screen
"+y - yank into the system clipboard register :q! or ZQ - quit and throw away unsaved
zt - position cursor on top of the screen changes
"+p - paste from the system clipboard
zb - position cursor on bottom of the screen register :wqa - write (save) and quit on all tabs
Ctrl + e - move screen down one line Marks and positions Search and replace
(without moving cursor)
:marks - list of marks /pattern - search for pattern
Ctrl + y - move screen up one line (without
moving cursor)
ma - set current position for mark A ?pattern - search backward for pattern
Ctrl + b - move screen up one page (cursor `a - jump to position of mark A \vpattern - 'very magic' pattern: non-
to last line) alphanumeric characters are interpreted as
y`a - yank text to position of mark A special regex symbols (no escaping needed)
Ctrl + f - move screen down one page
(cursor to first line) `0 - go to the position where Vim was n - repeat search in same direction
previously exited
Ctrl + d - move cursor and screen down N - repeat search in opposite direction
1/2 page `" - go to the position when last editing this
file :%s/old/new/g - replace all old with new
Ctrl + u - move cursor and screen up 1/2 throughout file
page `. - go to the position of the last change in
this file :%s/old/new/gc - replace all old with
Insert mode - inserting/appending text new throughout file with confirmations
`` - go to the position before the last jump
i - insert before the cursor :noh[lsearch] - remove highlighting of
:ju[mps] - list of jumps search matches
I - insert at the beginning of the line
Ctrl + i - go to newer position in jump list Search in multiple files
a - insert (append) after the cursor
Ctrl + o - go to older position in jump list :vim[grep] /pattern/
A - insert (append) at the end of the line {`{file}`} - search for pattern in
:changes - list of changes multiple files
o - append (open) a new line below the g, - go to newer position in change list :cn[ext] - jump to the next match
current line
g; - go to older position in change list :cp[revious] - jump to the previous
O - append (open) a new line above the match
current line Ctrl + ] - jump to the tag under cursor
:cope[n] - open a window containing the
ea - insert (append) at the end of the word list of matches
Ctrl + h - delete the character before the :ccl[ose] - close the quickfix window
cursor during insert mode
Tabs
Ctrl + w - delete word before the cursor
during insert mode :tabnew or :tabnew
{page.words.file} - open a file in a
Ctrl + j - add a line break at the cursor new tab
position during insert mode
Ctrl + wT - move the current split window
Ctrl + t - indent (move right) line one into its own tab
shiftwidth during insert mode
gt or :tabn[ext] - move to the next tab
Ctrl + d - de-indent (move left) line one
shiftwidth during insert mode gT or :tabp[revious] - move to the
previous tab
Ctrl + n - insert (auto-complete) next
match before the cursor during insert mode #gt - move to tab number #
Ctrl + p - insert (auto-complete) previous :tabm[ove] # - move current tab to the
match before the cursor during insert mode #th position (indexed from 0)
Ctrl + rx - insert the contents of register x :tabc[lose] - close the current tab and
all its windows
Ctrl + ox - Temporarily enter normal
mode to issue one normal-mode command x. :tabo[nly] - close all tabs except for the
current one
Esc or Ctrl + c - exit insert mode
:tabdo command - run the command on all
tabs (e.g. :tabdo q - closes all opened tabs)