You are on page 1of 1

Sponsor

A new terminal focused on developer productivity

Vim Cheat Sheet


Global Editing Macros
:h[elp] keyword - open help for keyword r - replace a single character. qa - record macro a

:sav[eas] file - save file as R - replace more than one character, until ESC is q - stop recording macro
pressed.
:clo[se] - close current pane @a - run macro a
J - join line below to the current one with one
:ter[minal] - open a terminal window @@ - rerun last run macro
space in between
K - open man page for word under the cursor
gJ - join line below to the current one without Cut and paste
space in between

Tip Run vimtutor in a terminal to learn the yy - yank (copy) a line


gwip - reflow paragraph
first Vim commands. 2yy - yank (copy) 2 lines
g~ - switch case up to motion
yw - yank (copy) the characters of the word from
gu - change to lowercase up to motion
Cursor movement the cursor position to the start of the next word
gU - change to uppercase up to motion
h - move cursor left yiw - yank (copy) word under the cursor
cc - change (replace) entire line
j - move cursor down yaw - yank (copy) word under the cursor and the
c$ or C - change (replace) to the end of the line space after or before it
k - move cursor up
ciw - change (replace) entire word y$ or Y - yank (copy) to end of line
l - move cursor right
cw or ce - change (replace) to the end of the p - put (paste) the clipboard after cursor
gj - move cursor down (multi-line text)
word
P - put (paste) before cursor
gk - move cursor up (multi-line text)
s - delete character and substitute text (same as
gp - put (paste) the clipboard after cursor and
H - move to top of screen cl)
leave cursor after the new text

M - move to middle of screen S - delete line and substitute text (same as cc)
gP - put (paste) before cursor and leave cursor

L - move to bottom of screen xp - transpose two letters (delete and paste) after the new text

w - jump forwards to the start of a word u - undo dd - delete (cut) a line

W - jump forwards to the start of a word (words U - restore (undo) last changed line 2dd - delete (cut) 2 lines
can contain punctuation) dw - delete (cut) the characters of the word from
Ctrl + r - redo
the cursor position to the start of the next word
e - jump forwards to the end of a word
. - repeat last command
E - jump forwards to the end of a word (words can diw - delete (cut) word under the cursor
contain punctuation) Marking text (visual mode) daw - delete (cut) word under the cursor and the

b - jump backwards to the start of a word space after or before it


v - start visual mode, mark lines, then do a
B - jump backwards to the start of a word (words command (like y-yank) :3,5d - delete lines starting from 3 to 5

can contain punctuation) V - start linewise visual mode

ge - jump backwards to the end of a word Tip You can also use the following characters
o - move to other end of marked area
to specify the range:
gE - jump backwards to the end of a word (words Ctrl + v - start visual block mode e.g.
can contain punctuation)
O - move to other corner of block :.,$d - From the current line to the end of
% - move cursor to matching character (default the file
supported pairs: '()', '{}', '[]' - use :h matchpairs aw - mark a word :.,1d - From the current line to the
beginning of the file
in vim for more info)
ab - a block with () :10,$d - From the 10th line to the beginning
of the file
0 - jump to the start of the line
aB - a block with {}
^ - jump to the first non-blank character of the
at - a block with <> tags
line :g/{pattern}/d - delete all lines containing
ib - inner block with () pattern
$ - jump to the end of the line
iB - inner block with {} :g!/{pattern}/d - delete all lines not containing
g_ - jump to the last non-blank character of the
pattern
line it - inner block with <> tags
d$ or D - delete (cut) to the end of the line
gg - go to the first line of the document Esc or Ctrl + c - exit visual mode
x - delete (cut) character
G - go to the last line of the document
Tip Instead of b or B one can also use ( or
5gg or 5G - go to line 5
{ respectively.
Indent text
gd - move to local declaration
>> - indent (move right) line one shiftwidth
gD - move to global declaration Visual commands << - de-indent (move left) line one shiftwidth
fx - jump to next occurrence of character x
> - shift text right >% - indent a block with () or {} (cursor on brace)
tx - jump to before next occurrence of character x
< - shift text left <% - de-indent a block with () or {} (cursor on
Fx - jump to the previous occurrence of character brace)
y - yank (copy) marked text
x
>ib - indent inner block with ()
d - delete marked text
Tx - jump to after previous occurrence of
>at - indent a block with <> tags
character x ~ - switch case
3== - re-indent 3 lines
; - repeat previous f, t, F or T movement u - change marked text to lowercase
=% - re-indent a block with () or {} (cursor on
, - repeat previous f, t, F or T movement, U - change marked text to uppercase
brace)
backwards

Registers =iB - re-indent inner block with {}


} - jump to next paragraph (or function/block,
when editing code) gg=G - re-indent entire buffer
:reg[isters] - show registers content
{ - jump to previous paragraph (or ]p - paste and adjust indent to current line
function/block, when editing code) "xy - yank into register x

zz - center cursor on screen


"xp - paste contents of register x Exiting
zt - position cursor on top of the screen "+y - yank into the system clipboard register
:w - write (save) the file, but don't exit
"+p - paste from the system clipboard register
zb - position cursor on bottom of the screen :w !sudo tee % - write out the current file using
sudo
Ctrl + e - move screen down one line (without
moving cursor) Tip Registers are being stored in ~/.viminfo, :wq or :x or ZZ - write (save) and quit
and will be loaded again on next restart of
Ctrl + y - move screen up one line (without vim. :q - quit (fails if there are unsaved changes)
moving cursor)
:q! or ZQ - quit and throw away unsaved
Ctrl + b - move screen up one page (cursor to changes
last line) Tip Special registers:
:wqa - write (save) and quit on all tabs
Ctrl + f - move screen down one page (cursor to 0 - last yank
first line) " - unnamed register, last delete or yank
% - current file name Search and replace
Ctrl + d - move cursor and screen down 1/2 # - alternate file name
* - clipboard contents (X11 primary) /pattern - search for pattern
page
+ - clipboard contents (X11 clipboard)
/ - last search pattern ?pattern - search backward for pattern
Ctrl + u - move cursor and screen up 1/2 page
: - last command-line
. - last inserted text \vpattern - 'very magic' pattern: non-
- - last small (less than a line) delete alphanumeric characters are interpreted as special
Tip Prefix a cursor movement command with = - expression register
regex symbols (no escaping needed)
a number to repeat it. For example, 4j _ - black hole register

moves down 4 lines. n - repeat search in same direction

Marks and positions N - repeat search in opposite direction


Insert mode - inserting/appending :%s/old/new/g - replace all old with new
text :marks - list of marks
throughout file
ma - set current position for mark A
i - insert before the cursor :%s/old/new/gc - replace all old with new
`a - jump to position of mark A throughout file with confirmations
I - insert at the beginning of the line
y`a - yank text to position of mark A :noh[lsearch] - remove highlighting of search
a - insert (append) after the cursor
matches
`0 - go to the position where Vim was previously
A - insert (append) at the end of the line
exited
o - append (open) a new line below the current
Search in multiple files
`" - go to the position when last editing this file
line
:vim[grep] /pattern/ {`{file}`} - search
`. - go to the position of the last change in this file for pattern in multiple files
O - append (open) a new line above the current
line `` - go to the position before the last jump

ea - insert (append) at the end of the word :ju[mps] - list of jumps e.g. :vim[grep] /foo/ **/*

Ctrl + h - delete the character before the cursor Ctrl + i - go to newer position in jump list
during insert mode :cn[ext] - jump to the next match
Ctrl + o - go to older position in jump list
Ctrl + w - delete word before the cursor during :cp[revious] - jump to the previous match
insert mode :changes - list of changes
:cope[n] - open a window containing the list of
Ctrl + j - add a line break at the cursor position g, - go to newer position in change list
matches
during insert mode
g; - go to older position in change list
:ccl[ose] - close the quickfix window
Ctrl + t - indent (move right) line one
Ctrl + ] - jump to the tag under cursor
shiftwidth during insert mode
Tabs
Ctrl + d - de-indent (move left) line one
Tip To jump to a mark you can either use a :tabnew or :tabnew {page.words.file} -
shiftwidth during insert mode
backtick ( ` ) or an apostrophe ( ' ). Using an open a file in a new tab
Ctrl + n - insert (auto-complete) next match apostrophe jumps to the beginning (first non-
before the cursor during insert mode Ctrl + wT - move the current split window into
blank) of the line holding the mark.
its own tab
Ctrl + p - insert (auto-complete) previous match
before the cursor during insert mode gt or :tabn[ext] - move to the next tab

Ctrl + rx - insert the contents of register x gT or :tabp[revious] - move to the previous


tab
Ctrl + ox - Temporarily enter normal mode to
issue one normal-mode command x. #gt - move to tab number #

Esc or Ctrl + c - exit insert mode :tabm[ove] # - move current tab to the #th
position (indexed from 0)

:tabc[lose] - close the current tab and all its


windows

:tabo[nly] - close all tabs except for the current


one

:tabdo command - run the command on all tabs


(e.g. :tabdo q - closes all opened tabs)

Working with multiple files Diff


:e[dit] file - edit a file in a new buffer zf - manually define a fold up to motion

:bn[ext] - go to the next buffer zd - delete fold under the cursor

:bp[revious] - go to the previous buffer za - toggle fold under the cursor

:bd[elete] - delete a buffer (close a file) zo - open fold under the cursor

:b[uffer]# - go to a buffer by index # zc - close fold under the cursor

:b[uffer] file - go to a buffer by file zr - reduce (open) all folds by one level

:ls or :buffers - list all open buffers zm - fold more (close) all folds by one level

:sp[lit] file - open a file in a new buffer and split window zi - toggle folding functionality

:vs[plit] file - open a file in a new buffer and vertically split window ]c - jump to start of next change

:vert[ical] ba[ll] - edit all buffers as vertical windows [c - jump to start of previous change

:tab ba[ll] - edit all buffers as tabs do or :diffg[et] - obtain (get) difference (from other buffer)

Ctrl + ws - split window dp or :diffpu[t] - put difference (to other buffer)

Ctrl + wv - split window vertically :diffthis - make current window part of diff

Ctrl + ww - switch windows :dif[fupdate] - update differences

Ctrl + wq - quit a window :diffo[ff] - switch off diff mode for current window

Ctrl + wx - exchange current window with next one


Tip The commands for folding (e.g. za ) operate on one level. To operate
Ctrl + w= - make all windows equal height & width
on all levels, use uppercase letters (e.g. zA ).
Ctrl + wh - move cursor to the left window (vertical split)

Ctrl + wl - move cursor to the right window (vertical split)


Tip To view the differences of files, one can directly start Vim in diff
Ctrl + wj - move cursor to the window below (horizontal split)
mode by running vimdiff in a terminal. One can even set this as git
Ctrl + wk - move cursor to the window above (horizontal split) difftool .

Ctrl + wH - make current window full height at far left (leftmost vertical
window)

Ctrl + wL - make current window full height at far right (rightmost vertical
window)

Ctrl + wJ - make current window full width at the very bottom


(bottommost horizontal window)

Ctrl + wK - make current window full width at the very top (topmost
horizontal window)

Additional Resources

Languages About the vim cheat sheet


This project aims to be one of the most accessible vim guides available. We made sure to
‫اﻟﻌﺮﺑﯿﺔ‬
support mobile, desktop, and other languages.
বাংলা

Català
❤ Please consider sponsoring this project ❤ !

You can read about how to contribute (and help improve) by viewing our README .
Čeština There you can see how to set up this project, or how to contribute a new language. Here
Dansk is a big thank you to our contributors!

Deutsch This project is licensed under The MIT License (MIT) .

English Other places to find this document


Esperanto This document was embedded in DuckDuckGo .
Español
More resources
Persian
Interactive Vim tutorial: Open Vim
Suomi
Vim quick reference from Vim help pages: quickref.txt
Français
List of all Vim ex ( : ) commands: ex-cmd-index
‫עברית‬

Hrvatski

Magyar

Bahasa Indonesia

Italiano

⽇本語

한국어

ြမန်မာ

Nederlands

Norsk

Polski

Português - Brasil

Português - Portugal

Romana

Русский

ංහල

Slovenčina

Svenska

ภาษาไทย

Türkçe

Українська

Tiếng Việt

简体中文

中文 (台灣)

Checkout the source on Github

version: 3.2.0

You might also like