Back to Top
Vim Cheat Sheet
Table of Contents
Ctrl+W Assignments
Leader Assignments
Keyboard Shortcuts
Cursor Movement
Insert Mode - ways to commence editing
Editing
NERDtree
Working with Multiple Files
Tabs
Marking text (visual mode)
Visual Commands
Marks
Cut and Paste
Registers
Search & Replace
Environment/Interface
Exiting
Ctrl+W Assignments
For an exhaustive list of all Ctrl+W syntax, click Vim documentation: windows
Ctrl+W +/- | increase/decrease window height; prefix with a number, e.g.: 20<C-w>+ |
Ctrl+W _ | increase/decrease window height; prefix with a number, e.g.: 50<C-w>_ |
Ctrl+W >/< | increase/decrease window width; prefix with a number, e.g.: 30<C-w>< |
Ctrl+W | | increase/decrease window width; prefix with a number, e.g.: 30<C-w>| |
Ctrl+W = | equalise width and height of all windows |
Ctrl+W s | Split current window in two horizontally |
Ctrl+W v | Split current window in two vertically |
Ctrl+W n | Create a new window and start editing an empty file in it. |
Ctrl+W Ctrl+J, Ctrl+W down | Move cursor to Nth window below current one. |
Ctrl+W Ctrl+k, Ctrl+W up | Move cursor to Nth window above current one. |
Ctrl+W Ctrl+H, Ctrl+W lft, Ctrl+W backsp | Move cursor to Nth window left of current one. |
Ctrl+W Ctrl+l, Ctrl+W right | Move cursor to Nth window right of current one. |
Ctrl+W Shift-T | Move buffer to a tab |
Leader Assignments
, F5 | NerdTree file manager using directory of current file |
, cd | Set working directory to path of current file |
, d | Duplicate current line |
, ev | Open .vimrc in a new tab for editing |
, fn | Echo currently edited file's name to system clipboard |
, ln , tn | Toggle appearance of line numbers between absolute consecutive order and relative to current line |
, n | Turn off find highlighting — :nohl |
, sv | source .vimrc (reload settings) |
, v | execute paste from system clipboard |
, y | paste from system clipboard |
, + (non-keypad) | vertical resize +5 columns |
, - (non-keypad) | vertical resize -5 columns |
Cursor Movement
h | move left |
j | move down |
k | move up |
l | move right |
M | move to middle of screen |
L | move to bottom of screen |
w | jump forwards to the start of a word |
W | jump forwards to the start of a word (words can contain punctuation) |
e | jump forwards to the end of a word |
E | jump forwards to the end of a word (words can contain punctuation) |
b | jump backwards to the start of a word |
B | jump backwards to the start of a word (words can contain punctuation) |
0 | jump to the start of the line |
^ | jump to the first non-blank character of the line |
$ | jump to the end of the line |
g_ | jump to the last non-blank character of the line |
gg | go to the first line of the document |
G | go to the last line of the document |
5G | go to line 5 |
fx | jump to next occurrence of character x |
tx | jump to before next occurrence of character x |
} | jump to next paragraph (or function/block, when editing code) |
{ | jump to previous paragraph (or function/block, when editing code) |
zz | center cursor on screen |
Ctrl+b | move back one full screen |
Ctrl+f | move forward one full screen |
Ctrl+d | move forward ½ a screen |
Ctrl+u | move back ½ a screen |
Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines. | |
Back to Table of Contents |
Insert Mode - ways to commence editing
i | insert before the cursor |
I | insert at the beginning of the line |
a | insert (append) after the cursor |
A | insert (append) at the end of the line |
o | append (open) a new line below the current line |
O | append (open) a new line above the current line |
ea | insert (append) at the end of the word |
Esc | exit insert mode |
Back to Table of Contents |
NERDtree
Files
o: | open in previous window |
go: | preview |
t: | open in new tab |
T: | open in new tab silently |
i: | open split |
gi: | preview split |
s: | open vsplit |
gs: | preview vsplit |
Directories
o: | open & close |
O: | recursively open |
x: | close parent |
X: | close all children recursively |
e: | explore selected directory |
Bookmarks
o: | open bookmark |
t: | open in new tab |
T: | open in new tab silently |
D: | delete bookmark |
Filesystem
C: | change tree root to selected dir |
u: | move tree root up a directory |
U: | move tree root up a directory but leave old root open |
r: | refresh cursor directory |
R: | refresh current root |
m: | show menu |
cd: | change the CWD to the selected dir |
CD | change tree root to CWD |
Command | Explain |
Tree navigation
p: | go to parent |
P: | go to root |
K: | go to first child |
J: | go to last child |
Ctrl+k: | go to previous sibling |
Ctrl+j: | go to next sibling |
Tree filtring
I: | hidden files (off) |
f: | file filters (on) |
F: | files (on) |
B: | bookmarks (off) |
Other Commands
q: | Close the NERDtree window |
A: | toggle zoom NERDtree window |
?: | toggle help |
Editing
r | replace a single character |
J | join line below to the current one |
cc or S | change (replace) entire line |
cw | change (replace) to the end of the word |
c$ | change (replace) to the end of the line |
s | delete character and substitute text |
xp | transpose two letters (delete and paste) |
u | undo |
Ctrl+R | redo |
. (period) | repeat last command |
Back to Table of Contents |
Working with Multiple Files
:e file | edit a file in a new buffer |
:bnext or :bn | go to the next buffer |
:bprev or :bp | go to the previous buffer |
:bd | delete a buffer (close a file) |
:ls | list all open buffers |
:sp file | open a file in a new buffer and split window |
:vsp file | open a file in a new buffer and vertically split window |
Ctrl + ws | split window |
Ctrl + ww | switch windows |
Ctrl + wq | quit a window |
Ctrl + wv | split window vertically |
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) |
Back to Table of Contents |
Marking text (visual mode)
v | start visual mode, mark lines, then do a command (like y-yank) |
V | start linewise visual mode |
o | move to other end of marked area |
Ctrl + v | start visual block mode |
O | move to other corner of block |
aw | mark a word |
ab | a block with () |
aB | a block with {} |
ib | inner block with () |
iB | inner block with {} |
Esc | exit visual mode |
Back to Table of Contents |
Visual Commands
> | shift text right |
< | shift text left |
y | yank (copy) marked text |
d | delete marked text |
~ (tilde) | switch case |
Back to Table of Contents |
Cut and Paste
yy | yank (copy) a line |
2yy | yank (copy) 2 lines |
yw | yank (copy) the characters of the word from the cursor position to the start of the next word |
y$ | yank (copy) to end of line |
p | put (paste) the clipboard after cursor |
P | put (paste) before cursor |
dd | delete (cut) a line |
2dd | delete (cut) 2 lines |
dw | delete (cut) the characters of the word from the cursor position to the start of the next word |
D | delete (cut) to the end of the line |
d$ | delete (cut) to the end of the line |
x | delete (cut) character |
Back to Table of Contents |
Marks
:marks | list if marks |
ma | set current position for mark A |
`a | jump to position of mark A |
y`a | yank text to position of mark A |
Back to Table of Contents |
Registers
:reg | show registers content |
"xy | yank into register x |
"xp | paste contents of register x |
Registers are stored in ~/.viminfo, and will be loaded again on next restart of vim. Register 0 contains always the value of the last yank command. | |
Back to Table of Contents |
Search & Replace
/pattern | search for pattern |
?pattern | search backward for pattern |
\vpattern | 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed) |
n | repeat search in same direction |
N | repeat search in opposite direction |
:%s/old/new/g | replace all old with new throughout file |
:%s/old/new/gc | replace all old with new throughout file with confirmations |
:noh | remove highlighting of search matches |
Back to Table of Contents |
Search in multiple files
:vimgrep /pattern/ {file} | search for pattern in multiple files e.g: :vimgrep /foo/ **/* |
:cn | jump to the next match |
:cp | jump to the previous match |
:copen | open a window containing the list of matches |
Back to Table of Contents |
Tabs
:tabnew or :tabnew file | open a file in a new tab |
Ctrl+wT | move the current split window into its own tab |
gt :tabn :tabnext | move to the next tab |
gT :tabprev :tabp | move to the previous tab |
#gt | move to the tab number # |
:tabmove # | move current tab to the #th position (indexed from 0) |
:tabc or :tabclose | close the current tab and all its windows |
:tabo or :tabonly | close all tabs except for the current one |
:tabdo | run the command on all tabs (e.g. :tabdo q - closes all opened tabs) |
Back to Table of Contents |
Exiting
:w | write [save] file but don't exit |
:wq | write [save] |
:q | quit [fails if file has changed] |
:q! | quit and throw away changes |
Back to Table of Contents |