Getting started
Exiting
Shortcut | Description |
---|---|
:qa | Close all files |
:qa! | Close all files, abandon changes |
:w | Save |
:wq /:x | Save and close file |
:q | Close file |
:q! | Close file, abandon changes |
ZZ | Save and quit |
ZQ | Quit without checking changes |
Navigating
Shortcut | Description |
---|---|
h j k l | Arrow keys |
<C-U> /<C-D> | Page up/page down |
Words
Shortcut | Description |
---|---|
b /w | Previous/next word |
e /ge | Previous/next end of word |
Line
Shortcut | Description |
---|---|
0 (zero) | Start of line |
^ | (after whitespace) |
$ | End of line |
Character
Shortcut | Description |
---|---|
fc | c |
Fc | c |
Document
Shortcut | Description |
---|---|
gg | First line |
G | Last line |
:n | n |
nG | n |
Window
Shortcut | Description |
---|---|
zz | Center this line |
H | Move to top of screen |
M | Move to middle of screen |
L | Move to bottom of screen |
Tab pages
Shortcut | Description |
---|---|
:tabedit [file] | Edit file in a new tab |
:tabfind [file] | Open file if exists in new tab |
:tabclose | Close current tab |
:tabs | List all tabs |
:tabfirst | Go to first tab |
:tablast | Go to last tab |
:tabn | Go to next tab |
:tabp | Go to previous tab |
Editing
Shortcut | Description |
---|---|
a | Append |
i | Insert |
o | Next line |
O | Previous line |
s | Delete char and insert |
S | Delete line and insert |
C | Delete until end of line and insert |
r | Replace one character |
R | Enter Replace mode |
u | Undo changes |
<C-R> | Redo changes |
Exiting insert mode
Shortcut | Description |
---|---|
Esc /<C-[> | Exit insert mode |
<C-C> | Exit insert mode, and abort current command |
Exiting insert mode
Shortcut | Description |
---|---|
Esc /<C-[> | Exit insert mode |
<C-C> | Exit insert mode, and abort current command |
Clipboard
Shortcut | Description |
---|---|
x | Delete character |
dd | (Cut) |
yy | (Copy) |
p | Paste |
P | Paste before |
Visual mode
Shortcut | Description |
---|---|
v | Enter visual mode |
V | Enter visual line mode |
<C-V> | Enter visual block mode |
In visual mode
Shortcut | Description |
---|---|
d /x | Delete selection |
s | Replace selection |
y | (Copy) |
See Operators for other things you can do.
Operators
Usage
Operators let you operate in a range of text (defined by motion). These are preformed in normal mode.
Shortcut | Description |
---|---|
d | w |
Operator | Motion |
Operators list
Shortcut | Description |
---|---|
d | Delete |
y | (copy) |
c | (delete then insert) |
> | Indent right |
< | Indent left |
g~ | Swap case |
gU | Uppercase |
gu | Lowercase |
! | Filter through external program |
See :help operator
Examples
Combine operators with motions to use them.
Shortcut | Description |
---|---|
d d | (repeat the letter) |
d w | Delete to next word |
d b | Delete to beginning of word |
2dd | Delete 2 lines |
d ip | (inside paragraph) |
(in visual mode)d | Delete selection |
See: :help motion.txt
Text objects
Usage
Text objects let you operate (with an operator) in or around text blocks (objects).
Operator | Inside | Object |
---|---|---|
v | i | p |
Operator | [i]nside or [a]round | Text object |
Text objects
Shortcut | Description |
---|---|
p | Paragraph |
w | Word |
s | Sentence |
[ ( { < | A [], (), or {} block |
' " ` | A quoted string |
b | A block [( |
B | A block in [{ |
t | A XML tag block |
Examples
Shortcut | Description |
---|---|
vip | Select paragraph |
vipipipip | Select more |
yip | Yank inner paragraph |
yap | Yank paragraph (including newline) |
dip | Delete inner paragraph |
cip | Change inner paragraph |
See Operators for other things you can do.
Diff
Shortcut | Description |
---|---|
gvimdiff file1 file2 [file3] | See differencies between files, in HMI |
Misc
Folds
Shortcut | Description |
---|---|
zo /zO | Open |
zc /zC | Close |
za /zA | Toggle |
zv | Open folds for this line |
zM | Close all |
zR | Open all |
zm | (foldlevel += 1) |
zr | (foldlevel -= 1) |
zx | Update folds |
Uppercase ones are recursive (eg, zO
is open recursively).
Navigation
Shortcut | Description |
---|---|
[( [{ [< | ( { < |
]) | Next |
[m | Previous method start |
[M | Previous method end |
Jumping
Shortcut | Description |
---|---|
<C-O> | Go back to previous location |
<C-I> | Go forward |
gf | Go to file in cursor |
Counters
Shortcut | Description |
---|---|
<C-A> | Increment number |
<C-X> | Decrement |
Windows
Shortcut | Description |
---|---|
z{height}<Cr> | {height} |
Tags
Shortcut | Description |
---|---|
:tag Classname | Jump to first definition of Classname |
<C-]> | Jump to definition |
g] | See all definitions |
<C-T> | Go back to last tag |
<C-O> <C-I> | Back/forward |
:tselect Classname | Find definitions of Classname |
:tjump Classname | Find definitions of Classname (auto-select 1st) |
Case
Shortcut | Description |
---|---|
~ | Toggle case (Case => cASE) |
gU | Uppercase |
gu | Lowercase |
gUU | gUgU |
guu | gugu |
Do these in visual or normal mode.
Marks
Shortcut | Description |
---|---|
`^ | Last position of cursor in insert mode |
`. | Last change |
`` | |
ma | a |
`a | a |
'a | a |
Misc
Shortcut | Description |
---|---|
. | Repeat last command |
]p | paste under the current indentation level |
Command line
Shortcut | Description |
---|---|
<C-R><C-W> | Insert current word into the command line |
<C-R>" | Paste from " register |
<C-X><C-F> | Auto-completion of path in insert mode |
Text alignment
:center [width]
:right [width]
:left
See :help formatting
Calculator
Shortcut | Description |
---|---|
<C-R>=128/2 | Shows the result of the division: '64' |
Do this in insert mode.
Exiting with an error
:cq
:cquit
Works like :qa
, but throws an error. Great for aborting Git commands.
Spell checking
Shortcut | Description |
---|---|
:set spell spelllang=en_us | Turn on US English spell checking |
]s | Move to next misspelled word after the cursor |
[s | Move to previous misspelled word before the cursor |
z= | Suggest spellings for the word under/after the cursor |
zg | Add word to spell list |
zw | Mark word as bad/mispelling |
zu C-X (Insert Mode) | Suggest words for bad word under cursor from spellfile |
See :help spell
Also see
- Vim cheatsheet (vim.rotrr.com)
- Vim documentation (vimdoc.sourceforge.net)
- Interactive Vim tutorial (openvim.com)
Comments for this cheatsheet. Write yours!