Global Marks
:help keyword - open help for keyword :marks - list of marks
:o file - open file ma - set current position for mark A
:saveas file - save file as `a - jump to position of mark A
:close - close current pane y`a - yank text to position of mark A
K - open man page for word under the
cursor
Macros
Cursor movement qa - record macro a
q - stop recording macro
h - move cursor left @a - run macro a
j - move cursor down @@ - rerun last run macro
k - move cursor up
l - move cursor right
H - move to top of screen Cut and paste
M - move to middle of screen
L - move to bottom of screen yy - yank (copy) a line
w - jump forwards to the start of a word 2yy - yank (copy) 2 lines
W - jump forwards to the start of a word yw - yank (copy) the characters of the
(words can contain punctuation) word from the cursor position to the start
e - jump forwards to the end of a word of the next word
E - jump forwards to the end of a word y$ - yank (copy) to end of line
(words can contain punctuation) p - put (paste) the clipboard after cursor
b - jump backwards to the start of a word P - put (paste) before cursor
B - jump backwards to the start of a word dd - delete (cut) a line
(words can contain punctuation) 2dd - delete (cut) 2 lines
% - move to matching character (default dw - delete (cut) the characters of the
supported pairs: '()', '{}', '[]' - use :h word from the cursor position to the start
matchpairs in vim for more info)
of the next word
0 - jump to the start of the line D - delete (cut) to the end of the line
^ - jump to the first non-blank character d$ - delete (cut) to the end of the line
of the line x - delete (cut) character
$ - jump to the end of the line
g_ - jump to the last non-blank character
of the line Exiting
gg - go to the first line of the document
G - go to the last line of the document :w - write (save) the file, but don't exit
5G - go to line 5 :w !sudo tee % - write out the current file
fx - jump to next occurrence of character x using sudo
tx - jump to before next occurrence of :wq or :x or ZZ - write (save) and quit
character x :q - quit (fails if there are unsaved
Fx - jump to previous occurence of changes)
character x :q! or ZQ - quit and throw away unsaved
Tx - jump to after previous occurence of changes
character x :wqa - write (save) and quit on all tabs
; - repeat previous f, t, F or T movement
, - repeat previous f, t, F or T movement,
backwards Search and replace
} - jump to next paragraph (or
function/block, when editing code)
{ - jump to previous paragraph (or /pattern - search for pattern
function/block, when editing code) ?pattern - search backward for pattern
zz - center cursor on screen \vpattern - 'very magic' pattern: non-
Ctrl + b - move back one full screen alphanumeric characters are interpreted
Ctrl + f - move forward one full screen as special regex symbols (no escaping
Ctrl + d - move forward 1/2 a screen needed)
Ctrl + u - move back 1/2 a screen n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new
Tip Prefix a cursor movement command with a
throughout file
number to repeat it. For example, 4jmoves down 4
:%s/old/new/gc - replace all old with new
lines.
throughout file with confirmations
:noh - remove highlighting of search
Insert mode - inserting/appending text matches
i - insert before the cursor
I - insert at the beginning of the line Search in multiple files
a - insert (append) after the cursor
A - insert (append) at the end of the line :vimgrep /pattern/ {file} - search for
o - append (open) a new line below the pattern in multiple files
current line
O - append (open) a new line above the
e.g. :vimgrep /foo/ **/*
current line
ea - insert (append) at the end of the word
Esc - exit insert mode :cn - jump to the next match
:cp - jump to the previous match
:copen - open a window containing the list
Editing of matches
r - replace a single character
Working with multiple files
J - join line below to the current one with
one space in between
gJ - join line below to the current one :e file - edit a file in a new buffer
without space in between :bnext or :bn - go to the next buffer
cc - change (replace) entire line :bprev or :bp - go to the previous buffer
cw - change (replace) to the end of the :bd - delete a buffer (close a file)
word :ls - list all open buffers
c$ - change (replace) to the end of the line :sp file - open a file in a new buffer and
s - delete character and substitute text split window
S - delete line and substitute text (same as :vsp file - open a file in a new buffer and
cc) vertically split window
xp - transpose two letters (delete and Ctrl + ws - split window
paste) Ctrl + ww - switch windows
u - undo Ctrl + wq - quit a window
Ctrl + r - redo Ctrl + wv - split window vertically
. - repeat last command Ctrl + wh - move cursor to the left window
(vertical split)
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)