You are on page 1of 1

Vim Cheat Sheet

Cursor movement Editing Cut and paste


h - move cursor left r - replace a single character yy - yank (copy) a line

j - move cursor down J - join line below to the current one 2yy - yank (copy) 2 lines

k - move cursor up cc - change (replace) entire line yw - yank (copy) word

l - move cursor right cw - change (replace) to the end of the word y$ - yank (copy) to end of line

w - jump forwards to the start of a word c$ - change (replace) to the end of the line p - put (paste) the clipboard after cursor

W - jump forwards to the start of a word (words s - delete character and substitute text P - put (paste) before cursor
can contain punctuation)
S - delete line and substitute text (same as cc) dd - delete (cut) a line
e - jump forwards to the end of a word
xp - transpose two letters (delete and paste) 2dd - delete (cut) 2 lines
E - jump forwards to the end of a word (words can
u - undo dw - delete (cut) word
contain punctuation)

b - jump backwards to the start of a word Ctrl + r - redo D - delete (cut) to the end of the line

B - jump backwards to the start of a word (words . - repeat last command d$ - delete (cut) to the end of the line

can contain punctuation)


x - delete (cut) character
Marking text (visual mode)
0 - jump to the start of the line
v - start visual mode, mark lines, then do a Exiting
^ - jump to the first non-blank character of the
command (like y-yank)
line :w - write (save) the file, but don't exit
V - start linewise visual mode
$ - jump to the end of the line :w !sudo tee % - write out the current file
o - move to other end of marked area using sudo
g_ - jump to the last non-blank character of the
line Ctrl + v - start visual block mode :wq or :x or ZZ - write (save) and quit

gg - go to the first line of the document O - move to other corner of block :q - quit (fails if there are unsaved changes)

G - go to the last line of the document aw - mark a word :q! or ZQ - quit and throw away unsaved

5G - go to line 5 changes
ab - a block with ()

fx - jump to next occurrence of character x aB - a block with {} Search and replace


tx - jump to before next occurrence of character ib - inner block with () /pattern - search for pattern
x
iB - inner block with {} ?pattern - search backward for pattern
} - jump to next paragraph (or function/block,
when editing code) Esc - exit visual mode \vpattern - 'very magic' pattern: non-
alphanumeric characters are interpreted as special
{ - jump to previous paragraph (or
function/block, when editing code)
Visual commands regex symbols (no escaping needed)

n - repeat search in same direction


Ctrl + b - move back one full screen > - shift text right
N - repeat search in opposite direction
Ctrl + f - move forward one full screen < - shift text left
:%s/old/new/g - replace all old with new
Ctrl + d - move forward 1/2 a screen y - yank (copy) marked text
throughout file
Ctrl + u - move back 1/2 a screen d - delete marked text
:%s/old/new/gc - replace all old with new
~ - switch case throughout file with confirmations
Tip Prefix a cursor movement command with
a number to repeat it. For example, 4j :noh - remove highlighting of search matches
moves down 4 lines.
Search in multiple files
Insert mode - inserting/appending
:vimgrep /pattern/ {file} - search for
text
pattern in multiple files

i - insert before the cursor


e.g. :vimgrep /foo/ **/*
I - insert at the beginning of the line

a - insert (append) after the cursor


:cn - jump to the next match
A - insert (append) at the end of the line
:cp - jump to the previous match
o - append (open) a new line below the current
:copen - open a window containing the list of
line
matches
O - append (open) a new line above the current
line

ea - insert (append) at the end of the word

Esc - exit insert mode

Working with multiple files Tabs


:e filename - edit a file in a new buffer :tabnew filename or :tabn filename - open a
file in a new tab
:bnext or :bn - go to the next buffer
Ctrl + wT - move the current split window into
:bprev or :bp - go to the previous buffer
its own tab

:bd - delete a buffer (close a file) gt or :tabnext or :tabn - move to the next

:ls - list all open buffers tab

gT or :tabprev or :tabp - move to the


:sp filename - open a file in a new buffer and split
previous tab
window
#gt - move to tab number #
:vsp filename - open a file in a new buffer and
vertically split window :tabmove # - move current tab to the #th

Ctrl + ws - split window position (indexed from 0)

:tabclose or :tabc - close the current tab


Ctrl + ww - switch windows
and all its windows
Ctrl + wq - quit a window
:tabonly or :tabo - close all tabs except for
Ctrl + wv - split window vertically the current one

Ctrl + wh - move cursor to the left window :tabdo command - run the command on all tabs
(vertical split) (e.g. :tabdo q - closes all opened tabs)

Ctrl + wl - move cursor to the right window


(vertical split)

Ctrl + wj - move cursor to the window below


(horizontal split)

Ctrl + wk - move cursor to the window above


(horizontal split)

Additional Resources

Languages About the vim cheat sheet


This project aims to be one of the most accessible vim guides available. We made sure
Português - Brasil
to support mobile, desktop, and other languages.
Deutsch
You can read about how to contribute (and help improve) by viewing our README.
Bahasa Indonesia There you can see how to set up this project, or how to contribute a new language. Here
is a big thank you to our contributors!
Español
This project is licensed under The MIT License (MIT).
Türkçe

ภาษาไทย Contributor Code of Conduct


繁體中文 This project strongly believes in having a code of conduct. Please see the code of
conduct page for more information.
한국어

Русский Other places to find this document

简体中文 This document was embedded in DuckDuckGo.

Italiano

Français

Українська

日本語

Romana

English

Checkout the source on Github

You might also like