0% found this document useful (0 votes)
189 views2 pages

Vim Cheat Sheet

This cheat sheet provides a concise summary of common Vim commands for editing, navigation, cutting/pasting, working with multiple files, and more. It includes commands for global commands, editing, macros, navigation, cutting/pasting, working with multiple files, indentation, marking/visual mode, folding, and diff tools. This cheat sheet is a helpful one-page reference for many basic to intermediate Vim commands.

Uploaded by

Raza Abid Abbasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views2 pages

Vim Cheat Sheet

This cheat sheet provides a concise summary of common Vim commands for editing, navigation, cutting/pasting, working with multiple files, and more. It includes commands for global commands, editing, macros, navigation, cutting/pasting, working with multiple files, indentation, marking/visual mode, folding, and diff tools. This cheat sheet is a helpful one-page reference for many basic to intermediate Vim commands.

Uploaded by

Raza Abid Abbasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Please consider sponsoring this project!

Vim Cheat Sheet


Global Editing Macros Working with multiple files
:h[elp] keyword - open help r - replace a single character. qa - record macro a :e[dit] file - edit a file in a new buffer
for keyword
R - replace more than one character, q - stop recording macro :bn[ext] -
go to the next buffer
:sav[eas] file - save file as until ESC is pressed.
@a - run macro a :bp[revious] -
go to the previous buffer
:clo[se] - close current pane J - join line below to the current one
with one space in between @@ - rerun last run macro :bd[elete] - delete a buffer (close a file)
:ter[minal] - open a terminal
window gJ - join line below to the current one Cut and paste :b[uffer]# - go to a buffer by index #
without space in between
K - open man page for word under the yy - yank (copy) a line :b[uffer] file - go to a buffer by file
cursor gwip - reflow paragraph
2yy - yank (copy) 2 lines :ls or :buffers - list all open buffers
Cursor movement g~ - switch case up to motion
yw - yank (copy) the characters of the :sp[lit] file - open a file in a new buffer and split window
h - move cursor left
gu - change to lowercase up to motion word from the cursor position to the
start of the next word :vs[plit] file - open a file in a new buffer and vertically split
j - move cursor down window
gU - change to uppercase up to motion yiw - yank (copy) word under the
k - move cursor up cursor :vert[ical] ba[ll] - edit all buffers as vertical windows
cc - change (replace) entire line
l - move cursor right C - change (replace) to the end of the yaw - yank (copy) word under the :tab ba[ll] - edit all buffers as tabs
cursor and the space after or before it
line
H - move to top of screen Ctrl + ws - split window
y$ - yank (copy) to end of line
M - move to middle of screen c$ - change (replace) to the end of the
line Ctrl + wv - split window vertically
p - put (paste) the clipboard after
L - move to bottom of screen ciw - change (replace) entire word cursor Ctrl + ww - switch windows
w - jump forwards to the start of a cw or ce - change (replace) to the end P - put (paste) before cursor Ctrl + wq - quit a window
word of the word
gp - put (paste) the clipboard after Ctrl + wx - exchange current window with next one
W - jump forwards to the start of a s - delete character and substitute text cursor and leave cursor after the new
word (words can contain punctuation) text Ctrl + w= - make all windows equal height & width
- delete line and substitute text
e - jump forwards to the end of a word S gP - put (paste) before cursor and
Ctrl + wh - move cursor to the left window (vertical split)
(same as cc) leave cursor after the new text
E - jump forwards to the end of a word xp - transpose two letters (delete and Ctrl + wl - move cursor to the right window (vertical split)
(words can contain punctuation) dd - delete (cut) a line
paste)
2dd - delete (cut) 2 lines Ctrl + wj - move cursor to the window below (horizontal split)
b - jump backwards to the start of a u - undo
word Ctrl + wk - move cursor to the window above (horizontal split)
U - restore (undo) last changed line dw - delete (cut) the characters of the
B - jump backwards to the start of a word from the cursor position to the
word (words can contain punctuation) start of the next word Ctrl + wH - make current window full height at far left (leftmost vertical
Ctrl + r - redo window)
ge - jump backwards to the end of a diw - delete (cut) word under the
word
. - repeat last command cursor Ctrl + wL - make current window full height at far right (rightmost
vertical window)
gE - jump backwards to the end of a Marking text (visual mode) daw - delete (cut) word under the
cursor and the space after or before it
Ctrl + wJ - make current window full width at the very bottom
word (words can contain punctuation) v - start visual mode, mark lines, then (bottommost horizontal window)
do a command (like y-yank)
% - move to matching character D - delete (cut) to the end of the line
(default supported pairs: '()', '{}', '[]' -
Ctrl + wK - make current window full width at the very top (topmost
V - start linewise visual mode horizontal window)
use :h matchpairs in vim for more d$ - delete (cut) to the end of the line
info) o - move to other end of marked area
x - delete (cut) character Diff
0 - jump to the start of the line Ctrl + v - start visual block mode zf - manually define a fold up to motion
Indent text
^ - jump to the first non-blank O - move to other corner of block zd - delete fold under the cursor
character of the line >> - indent (move right) line one
shiftwidth
aw - mark a word za - toggle fold under the cursor
$ - jump to the end of the line
<< - de-indent (move left) line one
ab - a block with () shiftwidth zo - open fold under the cursor
g_ - jump to the last non-blank
character of the line aB - a block with {} zc - close fold under the cursor
>% - indent a block with () or {}
gg - go to the first line of the (cursor on brace)
at - a block with <> tags zr - reduce (open) all folds by one level
document
>ib - indent inner block with ()
ib - inner block with () zm - fold more (close) all folds by one level
G - go to the last line of the document
>at - indent a block with <> tags
iB - inner block with {} zi - toggle folding functionality
5gg or 5G - go to line 5
3== - re-indent 3 lines
it - inner block with <> tags ]c - jump to start of next change
gd - move to local declaration
=% - re-indent a block with () or {}
Esc - exit visual mode (cursor on brace) [c - jump to start of previous change
gD - move to global declaration
Visual commands =iB - re-indent inner block with {} do or :diffg[et] - obtain (get) difference (from other buffer)
fx - jump to next occurrence of
character x > - shift text right dp or :diffpu[t] - put difference (to other buffer)
gg=G - re-indent entire buffer
tx - jump to before next occurrence of < - shift text left :diffthis - make current window part of diff
character x ]p - paste and adjust indent to
current line
y - yank (copy) marked text :dif[fupdate] - update differences
Fx - jump to previous occurence of
character x d - delete marked text Exiting :diffo[ff] - switch off diff mode for current window
Tx - jump to after previous occurence :w - write (save) the file, but don't exit
~ - switch case
of character x :w !sudo tee % - write out the
u - change marked text to lowercase current file using sudo
; - repeat previous f, t, F or T
movement U - change marked text to uppercase :wq or :x or ZZ - write (save) and
, - repeat previous f, t, F or T quit
movement, backwards Registers
:q - quit (fails if there are unsaved
:reg[isters] - show registers changes)
} - jump to next paragraph (or content
function/block, when editing code) :q! or ZQ - quit and throw away
"xy - yank into register x unsaved changes
{ - jump to previous paragraph (or
function/block, when editing code) "xp - paste contents of register x :wqa - write (save) and quit on all
zz - center cursor on screen tabs
"+y - yank into the system clipboard
register
Ctrl + e - move screen down one Search and replace
line (without moving cursor) "+p - paste from the system clipboard /pattern - search for pattern
register
Ctrl + y - move screen up one line ?pattern - search backward for
(without moving cursor) pattern
Marks and positions
Ctrl + b - move back one full screen :marks - list of marks \vpattern - 'very magic' pattern:
non-alphanumeric characters are
Ctrl + f - move forward one full ma - set current position for mark A interpreted as special regex symbols
screen (no escaping needed)
`a - jump to position of mark A
Ctrl + d - move forward 1/2 a n - repeat search in same direction
screen y`a - yank text to position of mark A
N - repeat search in opposite direction
Ctrl + u - move back 1/2 a screen `0 - go to the position where Vim was
previously exited :%s/old/new/g -
replace all old
Insert mode - inserting/appending text with new throughout file
`" - go to the position when last
i - insert before the cursor editing this file :%s/old/new/gc -
replace all old
with new throughout file with
I - insert at the beginning of the line `. - go to the position of the last confirmations
change in this file
a - insert (append) after the cursor :noh[lsearch] - remove
`` - go to the position before the last highlighting of search matches
A - insert (append) at the end of the jump
line Search in multiple files
:ju[mps] - list of jumps
o - append (open) a new line below the :vim[grep] /pattern/
current line Ctrl + i - go to newer position in {`{file}`} -
search for pattern in
jump list multiple files
O - append (open) a new line above the
current line Ctrl + o - go to older position in
jump list :cn[ext] - jump to the next match
ea - insert (append) at the end of the
word :changes - list of changes :cp[revious] - jump to the
previous match
Ctrl + h - delete the character g, - go to newer position in change
before the cursor during insert mode list :cope[n] - open a window
containing the list of matches
Ctrl + w - delete word before the g; - go to older position in change list
cursor during insert mode :ccl[ose] - close the quickfix
Ctrl + ] - jump to the tag under window
Ctrl + j - begin new line during cursor
insert mode Tabs
Ctrl + t - indent (move right) line :tabnew or :tabnew
one shiftwidth during insert mode {page.words.file} -
open a
file in a new tab
Ctrl + d - de-indent (move left) line
one shiftwidth during insert mode Ctrl + wT - move the current split
window into its own tab
Ctrl + n - insert (auto-complete)
next match before the cursor during gt or :tabn[ext] - move to the
insert mode next tab

Ctrl + p - insert (auto-complete) gT or :tabp[revious] - move


previous match before the cursor to the previous tab
during insert mode
#gt - move to tab number #
Ctrl + rx - insert the contents of
register x :tabm[ove] # - move current tab
to the #th position (indexed from 0)
Ctrl + ox - Temporarily enter
normal mode to issue one normal- :tabc[lose] - close the current
mode command x. tab and all its windows

Esc - exit insert mode :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)

You might also like