Recording the Way

Vim Cheatsheet

2018/01/02

Exiting(链接地址)

: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
h j k l Arrow keys
<C-U> / <C-D> Page up/page down

Words

b / w Previous/next word
e / ge Previous/next end of word

Line

0 (zero) Start of line
^ Start of line (after whitespace)
$ End of line

Document

gg First line
G Last line
:n Go to line n
nG Go to line n

Editing

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

Exiting insert mode

Esc / <C-[> Exit insert mode
<C-C> Exit insert mode, and abort current command

Clipboard

x Delete character
dd Delete line (Cut)
yy Yank line (Copy)
p Paste
P Paste before

Visual mode

v Enter visual mode
V Enter visual line mode
<C-V> Enter visual block mode

In visual mode

d / x Delete selection
s Replace selection
y Yank selection (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.

d w
Operator Motion

Operators list

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

See :help operator

Examples

Combine operators with motions to use them.

dd (repeat the letter) Delete current line
dw Delete to next word
db Delete to beginning of word
2dd Delete 2 lines
dip Delete a text object (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).

v i p
Operator [i]nside or [a]round Text object

Text objects

p Paragraph
w Word
s Sentence
[ ( { < A [], (), or {} block
' "
A quoted string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
| `b` | A block [( |
| `B` | A block in [{ |
| `t` | A XML tag block |
### Examples
| `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](https://devhints.io/vim#operators) for other things you can do.
## Misc
### Folds
| `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 |
Uppercase ones are recursive (eg, `zO` is open recursively).
### Navigation
| `[(` `[{` `[<` | previous `(` or `{` or `<` |
| -------------- | -------------------------- |
| `])` | next |
| `[m` | previous method start |
| `[M` | previous method end |
### Jumping
| `<C-O>` | Go back to previous location |
| ------- | ---------------------------- |
| `<C-I>` | Go forward |
| `gf` | go to file in cursor |
### Counters
| `<C-A>` | increment number |
| ------- | ---------------- |
| `<C-X>` | decrement |
### Windows
| `z{height}<Cr>` | Resize pane to `{height}` lines tall |
| --------------- | ------------------------------------ |
| | |
### Tags
| `: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
| `~` | toggle case (Case => cASE) |
| ----- | ------------------------------------ |
| `gU` | uppercase |
| `gu` | lowercase |
| `gUU` | uppercase current line (also `gUgU`) |
| `guu` | lowercase current line (also `gugu`) |
Do these in visual or normal mode.
### Marks
| ``^` | 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` |
### Misc
| `.` | repeat last command |
| ---- | ---------------------------------------- |
| `]p` | paste under the current indentation level |
| `zz` | Center this line |
### Command line
| `<C-R><C-W>` | insert current word into the command line |
| ------------ | ---------------------------------------- |
| `<C-R>"` | paste from “ register |
### Text alignment

:center [width]
:right [width]
:left

1
2
3
4
See `:help formatting`
### Calculator

=128/2

1
2
3
4
Do this in insert mode.
### Exiting with an error

:cq
:cquit

```

Works like :qa, but throws an error. Great for aborting Git commands.

CATALOG
  1. 1. Exiting(链接地址)
  2. 2. Navigating
    1. 2.1. Words
    2. 2.2. Line
    3. 2.3. Document
  3. 3. Editing
  4. 4. Exiting insert mode
  5. 5. Clipboard
  6. 6. Visual mode
    1. 6.1. In visual mode
  • Operators
    1. 1. Usage
    2. 2. Operators list
    3. 3. Examples
  • Text objects
    1. 1. Usage
    2. 2. Text objects