title | category | layout | tags | updated | weight | intro | |
---|---|---|---|---|---|---|---|
Vim |
Linux |
2017/sheet |
|
2017-08-26 |
-10 |
[Vim](http://www.vim.org/) is a very efficient text editor. This reference was made for Vim 8.0.
|
{: .-three-column}
{: .-prime}
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 |
{: .-shortcuts} |
| h
j
k
l
| Arrow keys |
| ^u
/ ^d
| Page up/page down |
{: .-shortcuts}
| b
/ w
| Previous/next word |
| e
/ ge
| Previous/next end of word |
{: .-shortcuts}
| 0
(zero) | Start of line |
| ^
| Start of line (after whitespace) |
| $
| End of line |
{: .-shortcuts}
| gg
| First line |
| G
| Last line |
| :n
| Go to line n
|
| nG
| Go to line n
|
{: .-shortcuts}
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 |
{: .-shortcuts} |
Shortcut | Description |
---|---|
Esc / ^[ |
Exit insert mode |
^c |
Exit insert mode, and abort current command |
{: .-shortcuts} |
Shortcut | Description |
---|---|
x |
Delete character |
--- | --- |
dd |
Delete line (Cut) |
yy |
Yank line (Copy) |
--- | --- |
p |
Paste |
P |
Paste before |
{: .-shortcuts} |
| v
| Enter visual mode |
| V
| Enter visual line mode |
| ^v
| Enter visual block mode |
{: .-shortcuts}
| d
/ x
| Delete selection |
| s
| Replace selection |
| y
| Yank selection (Copy) |
{: .-shortcuts}
See Operators for other things you can do.
{: .-three-column}
{: .-prime}
Operators let you operate in a range of text (defined by motion). These are preformed in normal mode. {: .-setup}
| d
| w
|
| Operator | Motion |
{: .-css-breakdown}
Shortcut | Description |
---|---|
d |
Delete |
y |
Yank (copy) |
c |
Change (delete then insert) |
--- | --- |
> |
Indent right |
< |
Indent left |
--- | --- |
g~ |
Swap case |
gU |
Uppercase |
gu |
Lowercase |
--- | --- |
! |
Filter through external program |
{: .-shortcuts} |
See :help operator
Combine operators with motions to use them. {: .-setup}
Shortcut | Description |
---|---|
d d |
(repeat the letter) Delete current line |
d w |
Delete to next word |
d b |
Delete to beginning of word |
2dd |
Delete 2 lines |
d ip |
Delete a text object (inside paragraph) |
(in visual mode) d |
Delete selection |
See: :help motion.txt
{: .-three-column}
{: .-prime}
Text objects let you operate (with an operator) in or around text blocks (objects). {: .-setup}
| v
| i
| p
|
| Operator | [i]nside or [a]round | Text object |
{: .-css-breakdown}
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 |
{: .-shortcuts} |
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 |
{: .-shortcuts} |
See Operators for other things you can do.
Shortcut | Description |
---|---|
zo / zO |
Open |
zc / zC |
Close |
za / zA |
Toggle |
--- | --- |
zv |
Open folds for this line |
--- | --- |
zM |
Close all |
zR |
Open all |
--- | --- |
zm |
Fold more (foldlevel += 1) |
zr |
Fold less (foldlevel -= 1) |
--- | --- |
zx |
Update folds |
{: .-shortcuts} |
Uppercase ones are recursive (eg, zO
is open recursively).
Shortcut | Description |
---|---|
[( [{ [< |
previous ( or { or < |
]) |
next |
--- | --- |
[m |
previous method start |
[M |
previous method end |
{: .-shortcuts} |
Shortcut | Description |
---|---|
^O |
Go back to previous location |
^I |
Go forward |
--- | --- |
gf |
go to file in cursor |
{: .-shortcuts} |
| ^A
| increment number |
| ^X
| decrement |
{: .-shortcuts}
| z{height}<Cr>
| Resize pane to {height}
lines tall |
Shortcut | Description |
---|---|
:tag Classname |
Jump to first definition of Classname |
--- | --- |
^] |
Jump to definition |
g] |
See all definitions |
^t |
Go back to last tag |
^o ^i |
Back/forward |
--- | --- |
:tselect Classname |
Find definitions of Classname |
:tjump Classname |
Find definitions of Classname (auto-select 1st) |
{: .-shortcuts} |
Shortcut | Description |
---|---|
~ |
toggle case (Case => cASE) |
gU |
uppercase |
gu |
lowercase |
--- | --- |
gUU |
uppercase current line (also gUgU ) |
guu |
lowercase current line (also gugu ) |
{: .-shortcuts} |
Do these in visual mode.
Shortcut | Description |
---|---|
`^ |
Last position of cursor in insert mode |
`. |
Last change |
`` |
Last jump |
--- | --- |
ma |
Mark this cursor position as a |
`a |
Jump to the cursor position a |
'a |
Jump to the beginning of the line with position a |
{: .-shortcuts} |
Shortcut | Description |
---|---|
. |
repeat last command |
]p |
paste under the current indentation level |
--- | --- |
zz |
Center this line |
{: .-shortcuts} |
Shortcut | Description |
---|---|
<C-r><C-w> |
insert current word into the command line |
<C-r>" |
paste from " register |
{: .-shortcuts} |
:center [width]
:right [width]
:left
See :help formatting
<C-r>=128/2
Do this in insert mode.
:cq
:cquit
Works like :qa
, but throws an error. Great for aborting Git commands.
- Vim cheatsheet (vim.rotrr.com)
- Vim documentation (vimdoc.sourceforge.net)
- Interactive Vim tutorial (openvim.com)