0% found this document useful (0 votes)
122 views

Vim Cheat Sheet

Uploaded by

Sudeep M C
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)
122 views

Vim Cheat Sheet

Uploaded by

Sudeep M C
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

Please consider sponsoring this project!

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
J - join line below to the q - stop recording macro :bn[ext] - go to the next buffer
:sav[eas] file - save current one with one space in
file as between @a - run macro a :bp[revious] - go to the previous buffer
:clo[se] - close current gJ - join line below to the @@ - rerun last run macro :bd[elete] - delete a buffer (close a file)
pane current one without space in
between Cut and paste :b[uffer]# - go to a buffer by index #
:ter[minal] - open a
terminal window gwip - reflow paragraph yy - yank (copy) a line :b[uffer] file - go to a buffer by file
K - open man page for word g~ - switch case up to motion 2yy - yank (copy) 2 lines :ls or :buffers - list all open buffers
under the cursor
gu - change to lowercase up yw - yank (copy) the :sp[lit] file - open a file in a new buffer and split
Cursor movement to motion characters of the word from window
the cursor position to the start
h - move cursor left gU - change to uppercase up of the next word :vs[plit] file - open a file in a new buffer and
to motion vertically split window
j - move cursor down y$ - yank (copy) to end of line
cc - change (replace) entire :vert[ical] ba[ll] - edit all buffers as vertical
k - move cursor up line p - put (paste) the clipboard windows
after cursor
l - move cursor right C - change (replace) to the :tab ba[ll] - edit all buffers as tabs
end of the line P - put (paste) before cursor
H - move to top of screen Ctrl + ws - split window
c$ - change (replace) to the dd - delete (cut) a line
M - move to middle of screen end of the line Ctrl + wv - split window vertically
2dd - delete (cut) 2 lines
L - move to bottom of screen ciw - change (replace) entire Ctrl + ww - switch windows
word dw - delete (cut) the
w - jump forwards to the start characters of the word from Ctrl + wq - quit a window
of a word cw - change (replace) to the the cursor position to the start
end of the word of the next word Ctrl + wx - exchange current window with next one
W - jump forwards to the start
of a word (words can contain s - delete character and D - delete (cut) to the end of Ctrl + w= - make all windows equal height & width
punctuation) substitute text the line
Ctrl + wh - move cursor to the left window (vertical
e - jump forwards to the end S - delete line and substitute d$ - delete (cut) to the end of
split)
of a word text (same as cc) the line
Ctrl + wl - move cursor to the right window (vertical
E - jump forwards to the end xp - transpose two letters x - delete (cut) character
split)
of a word (words can contain (delete and paste)
punctuation) Indent text Ctrl + wj - move cursor to the window below
u - undo (horizontal split)
b - jump backwards to the >> - indent (move right) line
start of a word U - restore (undo) last one shiftwidth
Ctrl + wk - move cursor to the window above
changed line (horizontal split)
B - jump backwards to the << - de-indent (move left) line
start of a word (words can Ctrl + r - redo one shiftwidth
contain punctuation) Diff
. - repeat last command >% - indent a block with () or zf - manually define a fold up to motion
% - move to matching {} (cursor on brace)
character (default supported Marking text (visual mode) zd - delete fold under the cursor
pairs: '()', '{}', '[]' - use :h >ib - indent inner block with
matchpairs in vim for more v - start visual mode, mark ()
za - toggle fold under the cursor
info) lines, then do a command
(like y-yank) >at - indent a block with <>
zo - open fold under the cursor
0 - jump to the start of the tags
line V - start linewise visual mode zc - close fold under the cursor
3== - re-indent 3 lines
^ - jump to the first non-blank o - move to other end of zr - reduce (open) all folds by one level
character of the line marked area =% - re-indent a block with ()
or {} (cursor on brace)
zm - fold more (close) all folds by one level
$ - jump to the end of the line Ctrl + v - start visual block
mode =iB - re-indent inner block
with {}
zi - toggle folding functionality
g_ - jump to the last non-
blank character of the line O - move to other corner of
gg=G - re-indent entire buffer ]c - jump to start of next change
block
gg - go to the first line of the [c - jump to start of previous change
document aw - mark a word ]p - paste and adjust indent
to current line
ab - a block with () do or :diffg[et] - obtain (get) difference (from
G - go to the last line of the
other buffer)
document Exiting
aB - a block with {}
:w - write (save) the file, but dp or :diffpu[t] - put difference (to other buffer)
5gg or 5G - go to line 5
at - a block with <> tags don't exit
:diffthis - make current window part of diff
gd - move to local declaration
ib - inner block with () :w !sudo tee % - write
out the current file using sudo :dif[fupdate] - update differences
gD - move to global
declaration iB - inner block with {} :wq or :x or ZZ - write :diffo[ff] - switch off diff mode for current window
(save) and quit
fx - jump to next occurrence it - inner block with <> tags
of character x :q - quit (fails if there are
Esc - exit visual mode
unsaved changes)
Visual commands
tx - jump to before next :q! or ZQ - quit and throw
occurrence of character x > - shift text right away unsaved changes

Fx - jump to previous < - shift text left :wqa - write (save) and quit
occurence of character x on all tabs
y - yank (copy) marked text
Tx - jump to after previous Search and replace
occurence of character x d - delete marked text
/pattern - search for
; - repeat previous f, t, F or T ~ - switch case pattern
movement
u - change marked text to ?pattern - search
, - repeat previous f, t, F or T lowercase backward for pattern
movement, backwards
U - change marked text to \vpattern - 'very magic'
} - jump to next paragraph uppercase pattern: non-alphanumeric
(or function/block, when characters are interpreted as
editing code) special regex symbols (no
Registers escaping needed)
{ - jump to previous :reg[isters] - show
paragraph (or function/block, registers content n - repeat search in same
when editing code) direction
"xy - yank into register x
zz - center cursor on screen N - repeat search in opposite
"xp - paste contents of direction
Ctrl + e - move screen down register x
one line (without moving :%s/old/new/g - replace
cursor) "+y - yank into the system all old with new throughout
clipboard register file
Ctrl + y - move screen up
one line (without moving "+p - paste from the system :%s/old/new/gc - replace
cursor) clipboard register all old with new throughout
file with confirmations
Ctrl + b - move back one Marks and positions
full screen :noh[lsearch] - remove
:marks - list of marks highlighting of search
Ctrl + f - move forward one matches
full screen ma - set current position for
mark A Search in multiple files
Ctrl + d - move forward 1/2 :vim[grep] /pattern/
a screen `a - jump to position of mark
A {`{file}`} - search for
Ctrl + u - move back 1/2 a pattern in multiple files
screen y`a - yank text to position of
mark A
:cn[ext] - jump to the next
Insert mode -
inserting/appending text `0 - go to the position where match
Vim was previously exited
i - insert before the cursor :cp[revious] - jump to
`" - go to the position when the previous match
I - insert at the beginning of last editing this file
the line :cope[n] - open a window
`. - go to the position of the containing the list of matches
a - insert (append) after the last change in this file
cursor :ccl[ose] - close the
`` - go to the position before quickfix window
A - insert (append) at the end the last jump
of the line Tabs
:ju[mps] - list of jumps
o - append (open) a new line :tabnew or :tabnew
below the current line Ctrl + i - go to newer {page.words.file} -
position in jump list open a file in a new tab
O - append (open) a new line
above the current line Ctrl + o - go to older Ctrl + wT - move the
position in jump list current split window into its
ea - insert (append) at the own tab
end of the word :changes - list of changes
gt or :tabn[ext] - move
Ctrl + h - delete the g, - go to newer position in to the next tab
character before the cursor change list
during insert mode gT or :tabp[revious] -
g; - go to older position in move to the previous tab
Ctrl + w - delete word change list
before the cursor during #gt - move to tab number #
insert mode Ctrl + ] - jump to the tag
under cursor :tabm[ove] # - move
Ctrl + j - begin new line current tab to the #th position
during insert mode (indexed from 0)

Ctrl + t - indent (move :tabc[lose] - close the


right) line one shiftwidth current tab and all its
during insert mode windows

Ctrl + d - de-indent (move :tabo[nly] - close all tabs


left) line one shiftwidth except for the current one
during insert mode
:tabdo command - run the
Ctrl + n - insert (auto- command on all tabs (e.g.
complete) next match before :tabdo q - closes all opened
the cursor during insert mode tabs)

Ctrl + p - insert (auto-


complete) previous match
before the cursor during
insert mode
Ctrl + rx - insert the
contents of register x

Esc - exit insert mode

You might also like