0% found this document useful (0 votes)
254 views3 pages

Vim Cheat Sheet

This cheat sheet summarizes many useful Vim commands organized into categories like global commands, editing commands, working with multiple files, macros, cutting and pasting, indentation, marking text, and folding. Some key commands include :help to open help, :saveas to save a file, r to replace a single character, dd to delete a line, p to paste, :split to open a file in a new buffer, Ctrl+w to switch windows, and za to toggle folding.

Uploaded by

Manus Human
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)
254 views3 pages

Vim Cheat Sheet

This cheat sheet summarizes many useful Vim commands organized into categories like global commands, editing commands, working with multiple files, macros, cutting and pasting, indentation, marking text, and folding. Some key commands include :help to open help, :saveas to save a file, r to replace a single character, dd to delete a line, p to paste, :split to open a file in a new buffer, Ctrl+w to switch windows, and za to toggle folding.

Uploaded by

Manus Human
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/ 3

Vim Cheat Sheet

Global Editing Macros Working with multiple files


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

Insert mode - inserting/appending `` - go to the position before :noh[lsearch] - remove


text highlighting of search matches
the last jump
i - insert before the cursor
:ju[mps] - list of jumps Search in multiple files
I - insert at the beginning of :vim[grep] /pattern/
the line Ctrl + i - go to newer
position in jump list {`{file}`} -
search for
a - insert (append) after the pattern in multiple files
cursor Ctrl + o - go to older position
in jump list
A - insert (append) at the end :cn[ext] - jump to the next
of the line :changes - list of changes match

o - append (open) a new line g, - go to newer position in :cp[revious] - jump to the


below the current line change list previous match

O - append (open) a new line g; - go to older position in :cope[n] - open a window


above the current line change list containing the list of matches

ea - insert (append) at the end Ctrl + ] - jump to the tag :ccl[ose] - close the
of the word under cursor quickfix window

Ctrl + h - delete the Tabs


character before the cursor :tabnew or :tabnew
during insert mode
{page.words.file} -
Ctrl + w - delete word before open a file in a new tab
the cursor during insert mode
Ctrl + wT - move the current
Ctrl + j - begin new line split window into its own tab
during insert mode
gt or :tabn[ext] - move to
Ctrl + t - indent (move right) the next tab
line one shiftwidth during
insert mode
gT or :tabp[revious] -
Ctrl + d - de-indent (move move to the previous tab
left) line one shiftwidth during
insert mode #gt - move to tab number #

Ctrl + n - insert (auto- :tabm[ove] # - move


complete) next match before current tab to the #th position
the cursor during insert mode (indexed from 0)

Ctrl + p - insert (auto- :tabc[lose] - close the


complete) previous match current tab and all its windows
before the cursor during insert
mode :tabo[nly] - close all tabs
except for the current one
Ctrl + rx - insert the
contents of register x :tabdo command - run the
command on all tabs (e.g.
Ctrl + ox - Temporarily :tabdo q - closes all opened
enter normal mode to issue one tabs)
normal-mode command x.

Esc - exit insert mode

You might also like