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

Vim Cheat Sheet

Uploaded by

Carlos
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)
14 views

Vim Cheat Sheet

Uploaded by

Carlos
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

Vim Cheat Sheet

Global Editing Macros Working with multiple files


:h[elp] keyword - open help for r - replace a single character. qa - record macro a :e[dit] file - edit a file in a new buffer
keyword
R - replace more than one character, until q - stop recording macro :bn[ext] - go to the next buffer
:sav[eas] file - save file as 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 #
K - open man page for word under the cursor without space in between
yy - yank (copy) a line :b[uffer] file - go to a buffer by file
Cursor movement gwip - reflow paragraph
2yy - yank (copy) 2 lines :ls or :buffers - list all open buffers
h - move cursor left g~ - switch case up to motion
yw - yank (copy) the characters of the word :sp[lit] file - open a file in a new buffer and split window
j - move cursor down gu - change to lowercase up to motion from the cursor position to the start of the
next word :vs[plit] file - open a file in a new buffer and vertically split window
k - move cursor up gU - change to uppercase up to motion yiw - yank (copy) word under the cursor :vert[ical] ba[ll] - edit all buffers as vertical windows
l - move cursor right cc - change (replace) entire line yaw - yank (copy) word under the cursor and :tab ba[ll] - edit all buffers as tabs
gj - move cursor down (multi-line text) c$ or C - change (replace) to the end of the the space after or before it
line Ctrl + ws - split window
gk - move cursor up (multi-line text) y$ or Y - yank (copy) to end of line
ciw - change (replace) entire word Ctrl + wv - split window vertically
H - move to top of screen p - put (paste) the clipboard after cursor
cw or ce - change (replace) to the end of the Ctrl + ww - switch windows
M - move to middle of screen word
P - put (paste) before cursor
Ctrl + wq - quit a window
L - move to bottom of screen s - delete character and substitute text (same gp - put (paste) the clipboard after cursor
and leave cursor after the new text Ctrl + wx - exchange current window with next one
as cl)
w - jump forwards to the start of a word
S - delete line and substitute text (same as gP - put (paste) before cursor and leave Ctrl + w= - make all windows equal height & width
W - jump forwards to the start of a word cc)
cursor after the new text
(words can contain punctuation) Ctrl + wh - move cursor to the left window (vertical split)
xp - transpose two letters (delete and paste) dd - delete (cut) a line
e - jump forwards to the end of a word Ctrl + wl - move cursor to the right window (vertical split)
u - undo 2dd - delete (cut) 2 lines
E - jump forwards to the end of a word Ctrl + wj - move cursor to the window below (horizontal split)
(words can contain punctuation) U - restore (undo) last changed line dw - delete (cut) the characters of the word
from the cursor position to the start of the Ctrl + wk - move cursor to the window above (horizontal split)
b - jump backwards to the start of a word Ctrl + r - redo next word

diw - delete (cut) word under the cursor Ctrl + wH - make current window full height at far left (leftmost vertical window)
B - jump backwards to the start of a word . - repeat last command
(words can contain punctuation) Ctrl + wL - make current window full height at far right (rightmost vertical window)
daw - delete (cut) word under the cursor and
ge - jump backwards to the end of a word Marking text (visual mode) the space after or before it
Ctrl + wJ - make current window full width at the very bottom (bottommost
v - start visual mode, mark lines, then do a horizontal window)
gE - jump backwards to the end of a word command (like y-yank) :3,5d - delete lines starting from 3 to 5
(words can contain punctuation) Ctrl + wK - make current window full width at the very top (topmost horizontal
V - start linewise visual mode window)
% - move cursor to matching character :g/{pattern}/d - delete all lines
(default supported pairs: '()', '{}', '[]' - use :h o - move to other end of marked area containing pattern
Diff
matchpairs in vim for more info)
Ctrl + v - start visual block mode :g!/{pattern}/d - delete all lines not zf - manually define a fold up to motion
0 - jump to the start of the line containing pattern
O - move to other corner of block d$ or D - delete (cut) to the end of the line zd - delete fold under the cursor
^ - jump to the first non-blank character of
the line aw - mark a word x - delete (cut) character za - toggle fold under the cursor
$ - jump to the end of the line ab - a block with () zo - open fold under the cursor
Indent text
g_ - jump to the last non-blank character of aB - a block with {} >> - indent (move right) line one shiftwidth zc - close fold under the cursor
the line
at - a block with <> tags << - de-indent (move left) line one shiftwidth zr - reduce (open) all folds by one level
gg - go to the first line of the document
ib - inner block with () >% - indent a block with () or {} (cursor on zm - fold more (close) all folds by one level
G - go to the last line of the document brace)
iB - inner block with {} zi - toggle folding functionality
5gg or 5G - go to line 5 <% - de-indent a block with () or {} (cursor
it - inner block with <> tags on brace) ]c - jump to start of next change
gd - move to local declaration
Esc or Ctrl + c - exit visual mode >ib - indent inner block with () [c - jump to start of previous change
gD - move to global declaration
Visual commands >at - indent a block with <> tags do or :diffg[et] - obtain (get) difference (from other buffer)
fx - jump to next occurrence of character x
> - shift text right 3== - re-indent 3 lines dp or :diffpu[t] - put difference (to other buffer)
tx - jump to before next occurrence of
character x < - shift text left =% - re-indent a block with () or {} (cursor on :diffthis - make current window part of diff
brace)
Fx - jump to the previous occurrence of y - yank (copy) marked text :dif[fupdate] - update differences
character x =iB - re-indent inner block with {}
d - delete marked text :diffo[ff] - switch off diff mode for current window
Tx - jump to after previous occurrence of gg=G - re-indent entire buffer
character x ~ - switch case
]p - paste and adjust indent to current line
; - repeat previous f, t, F or T movement u - change marked text to lowercase
, - repeat previous f, t, F or T movement, U - change marked text to uppercase Exiting
backwards :w - write (save) the file, but don't exit
Registers
} - jump to next paragraph (or :w !sudo tee % - write out the current
function/block, when editing code) :reg[isters] - show registers content file using sudo
{ - jump to previous paragraph (or "xy - yank into register x :wq or :x or ZZ - write (save) and quit
function/block, when editing code)
"xp - paste contents of register x :q - quit (fails if there are unsaved changes)
zz - center cursor on screen
"+y - yank into the system clipboard register :q! or ZQ - quit and throw away unsaved
zt - position cursor on top of the screen changes
"+p - paste from the system clipboard
zb - position cursor on bottom of the screen register :wqa - write (save) and quit on all tabs
Ctrl + e - move screen down one line Marks and positions Search and replace
(without moving cursor)
:marks - list of marks /pattern - search for pattern
Ctrl + y - move screen up one line (without
moving cursor)
ma - set current position for mark A ?pattern - search backward for pattern
Ctrl + b - move screen up one page (cursor `a - jump to position of mark A \vpattern - 'very magic' pattern: non-
to last line) alphanumeric characters are interpreted as
y`a - yank text to position of mark A special regex symbols (no escaping needed)
Ctrl + f - move screen down one page
(cursor to first line) `0 - go to the position where Vim was n - repeat search in same direction
previously exited
Ctrl + d - move cursor and screen down N - repeat search in opposite direction
1/2 page `" - go to the position when last editing this
file :%s/old/new/g - replace all old with new
Ctrl + u - move cursor and screen up 1/2 throughout file
page `. - go to the position of the last change in
this file :%s/old/new/gc - replace all old with
Insert mode - inserting/appending text new throughout file with confirmations
`` - go to the position before the last jump
i - insert before the cursor :noh[lsearch] - remove highlighting of
:ju[mps] - list of jumps search matches
I - insert at the beginning of the line
Ctrl + i - go to newer position in jump list Search in multiple files
a - insert (append) after the cursor
Ctrl + o - go to older position in jump list :vim[grep] /pattern/
A - insert (append) at the end of the line {`{file}`} - search for pattern in
:changes - list of changes multiple files
o - append (open) a new line below the g, - go to newer position in change list :cn[ext] - jump to the next match
current line
g; - go to older position in change list :cp[revious] - jump to the previous
O - append (open) a new line above the match
current line Ctrl + ] - jump to the tag under cursor
:cope[n] - open a window containing the
ea - insert (append) at the end of the word list of matches

Ctrl + h - delete the character before the :ccl[ose] - close the quickfix window
cursor during insert mode
Tabs
Ctrl + w - delete word before the cursor
during insert mode :tabnew or :tabnew
{page.words.file} - open a file in a
Ctrl + j - add a line break at the cursor new tab
position during insert mode
Ctrl + wT - move the current split window
Ctrl + t - indent (move right) line one into its own tab
shiftwidth during insert mode
gt or :tabn[ext] - move to the next tab
Ctrl + d - de-indent (move left) line one
shiftwidth during insert mode gT or :tabp[revious] - move to the
previous tab
Ctrl + n - insert (auto-complete) next
match before the cursor during insert mode #gt - move to tab number #
Ctrl + p - insert (auto-complete) previous :tabm[ove] # - move current tab to the
match before the cursor during insert mode #th position (indexed from 0)

Ctrl + rx - insert the contents of register x :tabc[lose] - close the current tab and
all its windows
Ctrl + ox - Temporarily enter normal
mode to issue one normal-mode command x. :tabo[nly] - close all tabs except for the
current one
Esc or Ctrl + c - exit insert mode
:tabdo command - run the command on all
tabs (e.g. :tabdo q - closes all opened tabs)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy