Vim Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。
▼/▶ Cursor ▽/▷ Target
┌───────────── |
├───────────── 0 $ ──────────────┐
│ ┌────────── ^ fe ────────┐ │
│ │ ┌─────── Fo te ───────┐│ │
│ │ │┌────── To 30| ───┐ ││ │
│ │ ││ ┌──── ge w ───┐ │ ││ │
│ │ ││ │ ┌── b e ─┐ │ │ ││ │
│ │ ││ │ │ ┌h l┐ │ │ │ ││ │
▽ ▽ ▽▽ ▽ ▽ ▽▼ ▼▽ ▽ ▽ ▽ ▽▽ ▽
echo "A cheatsheet from quickref.me"
- SCREEN 1 START
┌─┬─────────▷ #!/usr/bin/python
│ │ ┌───▷
│ │ │ print("Hello")
│ │ { } ▶ print("Vim")
│ │ │ print("!")
│ │ └─▷
│ │ ┌───┬───▷ print("Welcome")
G gg H M L k j ▶ print("to")
│ │ └─▷ print("cheatsheets.zip")
│ │ print("/vim")
│ │
│ └─────▷
│ - SCREEN 1 END
└──────────────▷ print("SCREEN 2")
| Shortcut | Description |
|---|---|
h | j | k | l | Arrow keys |
<C-u> / <C-d> | Half-page up/down |
<C-b> / <C-f> | Page up/down |
{.shortcuts}
| Shortcut | Description |
|---|---|
b / w | Previous/Next word |
ge / e | Previous/Next end of word |
{.shortcuts}
| Shortcut | Description |
|---|---|
0 (zero) / $ | Start/End of line |
^ | Start of line (non-blank) |
{.shortcuts}
| Shortcut | Description |
|---|---|
Fe / fe | Move to previous/next e |
To / to | Move before/after previous/next o |
| <code>|</code>/ <code>n|</code> | Go to first/nth column |
{.shortcuts}
| Shortcut | Description |
|---|---|
gg / G | First/Last line |
:n | nG | Go to line n |
} / { | Next/Previous empty line |
{.shortcuts}
| Shortcut | Description |
|---|---|
H / M / L | Top/Middle/Bottom screen |
zt / zz / zb | Top/Center/Bottom this line |
{.shortcuts}
| Shortcut | Description |
|---|---|
i / a | Insert before/after cursor |
I / A | Insert start/end of line |
o / O (letter) | Insert new line below/above |
s / S | Delete char/line and insert |
C / cc | Change to end of/current line |
gi | Insert at last insert point |
Esc | <C-[> | Exit insert mode |
{.shortcuts}
| Shortcut | Description |
|---|---|
:w | Save |
:q | Close file |
:wq | :x | ZZ | Save and quit |
:wqa | Save and quit all files |
:q! | ZQ | Force quit |
:qa | Close all files |
:qa! | Force quit all files |
:w now.txt | Write to now.txt |
:sav new.txt | Save and edit new.txt |
:w !sudo tee % | Write to readonly file |
{.shortcuts}
| Shortcut | Description |
|---|---|
r | Replace one character |
R | Enter Replace mode |
u / 3u | Undo changes 1 / 3 times |
U | Undo changes on one line |
J | Join with next line |
<C-r> / 5 <C-r> | Redo changes 1 / 5 times |
{.shortcuts}
| Shortcut | Description |
|---|---|
x | Delete character (Cut) |
p / P | Paste after/before |
xp | Swap two characters |
D | Delete to end of line (Cut) |
dw | Delete word (Cut) |
dd | Delete line (Cut) |
ddp | Swap two lines |
yy | Yank line (Copy) |
"*p | "+p | Paste from system clipboard |
"*y | "+y | Paste to system clipboard |
{.shortcuts}
| Shortcut | Description |
|---|---|
d | x | Delete selection (Cut) |
s | Replace selection |
y | Yank selection (Copy) |
{.shortcuts}
| Shortcut | Description |
|---|---|
. | Repeat last command |
; | Repeat latest f, t, F or T |
, | Repeat latest f, t, F or T reversed |
& | Repeat last :s |
@: | Repeat a command-line command |
{.shortcuts}
| Shortcut | Description |
|---|---|
v | Enter visual mode |
V | Enter visual line mode |
<C-v> | Enter visual block mode |
ggVG | Select all text |
> / < | Shift text right/left |
{.shortcuts}
| - | - |
|---|---|
qi | Record macro i |
q | Stop recording macro |
@i | Run macro i |
7@i | Run macro i 7 times |
@@ | Repeat last macro |
{.shortcuts}
You can save macro for any letters not just i
| Shortcut | Description |
|---|---|
d | Delete |
y | Yank (copy) |
c | Change (delete then insert) |
p | Paste |
= | Formats code |
g~ | Toggle case |
gU | Uppercase |
gu | Lowercase |
> | Indent right |
< | Indent left |
! | Filter through external program |
| Combination | Description |
|---|---|
d<yel>d</yel> | Delete current line |
d<yel>j</yel> | Delete two lines |
d<yel>w</yel> | Delete to next word |
d<yel>b</yel> | Delete to beginning of word |
d<yel>fa</yel> | Delete until a char |
d<yel>/hello</yel> | Delete until hello |
c<yel>c</yel> | Change current line, synonym with S |
y<yel>y</yel> | Copy current line |
><yel>j</yel> | Indent 2 lines |
ggd<yel>G</yel> | Delete a complete document |
gg=<yel>G</yel> | Indent a complete document |
ggy<yel>G</yel> | Copy a whole document |
{.show-header}
[count] <operator> <motion>
<operator> [count] <motion>
| Combination | Description |
|---|---|
2d<yel>d</yel> | Delete 2 lines |
6y<yel>y</yel> | Copy 6 lines |
d3<yel>w</yel> | Delete 3 words |
d5<yel>j</yel> | Delete 5 lines downwards |
>4<yel>k</yel> | Indent 4 lines upwards |
| Shortcut | Description | - |
|---|---|---|
v | <pur>i</pur> / <pur>a</pur> | <yel>p</yel> |
| Operator | <pur>i</pur>nner / <pur>a</pur>round | Text object |
Operate with an operator inner or around text blocks
| Shortcut | Description |
|---|---|
| <yel>p</yel> | Paragraph |
| <yel>w</yel> | Word |
| <yel>W</yel> | WORD <br/>(surrounded by whitespace) |
| <yel>s</yel> | Sentence |
| <yel>[</yel> <yel>(</yel> <yel>{</yel> <yel><</yel> | A [], (), or {} block |
| <yel>]</yel> <yel>)</yel> <yel>}</yel> <yel>></yel> | A [], (), or {} block |
| <yel>'</yel> <yel>"</yel> <yel>`</yel> | A quoted string |
| <yel>b</yel> | A block [( |
| <yel>B</yel> | A block in [{ |
| <yel>t</yel> | A HTML tag block |
See :help text-objects
| Shortcut | Description |
|---|---|
d<pur>i</pur><yel>w</yel> | Delete inner word |
d<pur>i</pur><yel>s</yel> | Delete inner sentence |
d<pur>i</pur><yel>"</yel> | Delete in quotes |
d<pur>a</pur><yel>"</yel> | Delete in quotes (including quotes) |
d<pur>i</pur><yel>p</yel> | Delete a paragraph |
| Shortcut | Description |
|---|---|
v<pur>i</pur><yel>"</yel> | Select inner quotes "...{.underline}" |
v<pur>a</pur><yel>"</yel> | Select quotes "..."{.underline} |
v<pur>i</pur><yel>[</yel> | Select inner brackets [...{.underline}] |
v<pur>a</pur><yel>[</yel> | Select brackets [...]{.underline} |
v<pur>i</pur><yel>w</yel> | Select inner word |
v<pur>i</pur><yel>p</yel> | Select inner paragraph |
v<pur>i</pur><yel>p</yel><pur>i</pur><yel>p</yel> | Select more paragraph |
| Shortcut | Description |
|---|---|
c<pur>i</pur><yel>w</yel> | Change inner word |
c<pur>i</pur><yel>"</yel> | Change inner quotes |
c<pur>i</pur><yel>t</yel> | Change inner tags (HTML) |
c<pur>i</pur><yel>p</yel> | Change inner paragraph |
y<pur>i</pur><yel>p</yel> | Yank inner paragraph |
y<pur>a</pur><yel>p</yel> | Yank paragraph (including newline) |
| - | - |
|---|---|
:e file | Edit a file in a new buffer |
:bn | Go to the next buffer |
:bp | Go to the previous buffer |
:bd | Remove file from buffer list |
:b 5 | Open buffer #5 |
:b file | Go to a buffer by file |
:ls | List all open buffers |
:sp file | Open and split window |
:vs file | Open and vertically split window |
:hid | Hide this buffer |
:wn | Write file and move to next |
:tab ba | Edit all buffers as tabs |
| - | - |
|---|---|
<C-w> s | Split window |
<C-w> v | Split window vertically |
<C-w> w | Switch windows |
<C-w> q | Quit a window |
<C-w> T | Break out into a new tab |
<C-w> x | Swap current with next |
<C-w> - / + | Decrease/Increase height |
<C-w> < / > | Decrease/Increase width |
<C-w> <code>|</code> | Max out the width |
<C-w> _ | Max out the height |
<C-w> = | Equally high and wide |
<C-w> h / l | Go to the left/right window |
<C-w> j / k | Go to the up/down window |
{.shortcuts}
| Shortcut | Description |
|---|---|
:tabe [file] | <yel>E</yel>dit file in a new tab |
:tabf [file] | Open if exists in new tab |
:tabc | <yel>C</yel>lose current tab |
:tabo | Close <yel>o</yel>ther tabs |
:tabs | List all <yel>tabs</yel> |
:tabr | Go to fi<yel>r</yel>st tab |
:tabl | Go to <yel>l</yel>ast tab |
:tabm 0 | <yel>M</yel>ove to position 0 |
:tabn | Go to <yel>n</yel>ext tab |
:tabp | Go to <yel>p</yel>revious tab |
| Shortcut | Description |
|---|---|
gt | Go to <yel>n</yel>ext tab |
gT | Go to <yel>p</yel>revious tab |
2gt | Go to tab number 2 |
{.shortcuts}
| - | - |
|---|---|
/foo | Search forward |
/foo\c | Search forward (case insensitive) |
?foo | Search backward |
/\v\d+ | Search with regex |
n | Next matching search pattern |
N | Previous match |
* | Search for current word forward |
# | Search for current word backward |
{.shortcuts}
:[range]s/{pattern}/{str}/[flags]
:s/old/new | Replace first |
:s/old/new/g | Replace all |
:s/\vold/new/g | Replace all with regex |
:s/old/new/gc | replace all (Confirm) |
:s/old/new/i | Ignore case replace first |
:2,6s/old/new/g | Replace between lines 2-6 |
:%s/{pattern}/{str}/[flags]
:%s/old/new | Replace first |
:%s/old/new/g | Replace all |
:%s/old/new/gc | Replace all (Confirm) |
:%s/old/new/gi | Replace all (ignore case) |
:%s/\vold/new/g | Replace all with regex |
| - | - |
|---|---|
% | Entire file |
’<,’> | Current selection |
5 | Line 5 |
5,10 | Lines 5 to 10 |
$ | Last line |
2,$ | Lines 2 to Last |
. | Current line |
,3 | Next 3 lines |
-3, | Forward 3 lines |
:[range]g/{pattern}/[command]
:g/foo/d | Delete lines containing foo |
:g!/foo/d | Delete lines not containing foo |
:g/^\s*$/d | Delete all blank lines |
:g/foo/t$ | Copy lines containing foo to EOF |
:g/foo/m$ | Move lines containing foo to EOF |
:g/^/m0 | Reverse a file |
:g/^/t. | Duplicate every line |
:[range]v/{pattern}/[command]
:v/foo/d | Delete lines not containing foo<br/>(also :g!/foo/d) |
| - | - |
|---|---|
g | Replace all occurrences |
i | Ignore case |
I | Don't ignore case |
c | Confirm each substitution |
| - | - |
|---|---|
& | \0 | Replace with the whole matched |
\1...\9 | Replace with the group 0-9 |
\u | Uppercase next letter |
\U | Uppercase following characters |
\l | Lowercase next letter |
\L | Lowercase following characters |
\e | End of \u, \U, \l and \L |
\E | End of \u, \U, \l and \L |
:s/a\|b/xxx\0xxx/g # Modifies "a b" to "xxxaxxx xxxbxxx"
:s/test/\U& file/ # Modifies "test" to "TEST FILE"
:s/\(test\)/\U\1\e file/ # Modifies "test" to "TEST file"
:s/\v([abc])([efg])/\2\1/g # Modifies "af fa bg" to "fa fa gb"
:s/\v\w+/\u\0/g # Modifies "bla bla" to "Bla Bla"
:s/\v([ab])|([cd])/\1x/g # Modifies "a b c d" to "ax bx x x"
:%s/.*/\L&/ # Modifies "HTML" to "html"
:s/\v<(.)(\w*)/\u\1\L\2/g # Make every first letter of a word uppercase
:%s/^\(.*\)\n\1/\1/ # Remove duplicate lines
:%s/<\/\=\(\w\+\)\>/\U&/g # Convert HTML-Tags to uppercase
:g/^pattern/s/$/mytext # Find and append text to the end
:g/pattern/norm! @i # Run a macro on matching lines
/^\(.*\)\(\r\?\n\1\)\+$ # View the duplicates lines
/\v^(.*)(\r?\n\1)+$ # View the duplicates lines (very magic)
:v/./,/./-j # Compress blank lines into a blank line
:g/<p1>/,/<p2>/d # Delete inclusively from <p1> to <p2>
$ vimdiff file1 file2 [file3]
$ vim -d file1 file2 [file3]
:[range]diffget [bufspec]
:[range]diffput [bufspec]
| Shortcut | Description |
|---|---|
do / :diffget | Obtain (get) difference |
dp / :diffput | Put difference |
:dif | Re-scan differences |
:diffo | Switch off diff mode |
:1,$+1diffget | Get all differences |
ZQ | Quit without changes |
{.shortcuts}
See: Ranges
| 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}
| Shortcut | Description |
|---|---|
]c | Next difference |
[c | Previous difference |
{.shortcuts}
The Quickfix List is primarily used to navigate a list of errors/warnings (or file locations) generated by a compiler or linter.
| Shortcut | Description |
|---|---|
:copen | Open the quickfix window |
:cclose | Close the quickfix window |
:cnext | Go to the next error/location (:cn also works) |
:cprevious | Go to the previous error/location (:cp also works) |
:clist | List all errors/locations in the list |
:cf [file] | Populate the list with errors from a file (e.g., a compiler log) |
The :cdo (quickfix do) and :cfdo (quickfix file do) commands execute a command in every file listed in the quickfix list. :cdo iterates over every location in the list, while :cfdo iterates over every unique file in the list.
| Command | Description |
|---|---|
:cdo [cmd] | Execute [cmd] for every location in the quickfix list. |
:cfdo [cmd] | Execute [cmd] for every unique file in the quickfix list. |
| Shortcut | Description |
|---|---|
vU | Uppercase character |
vu | Lowercase character |
~ | Toggle case character |
viw U | Uppercase word |
viw u | Lowercase word |
viw ~ | Toggle case word |
VU / gUU | Uppercase line |
Vu / guu | Lowercase line |
V~ / g~~ | Toggle case line |
gggUG | Uppercase all text |
ggguG | Lowercase all text |
ggg~G | Toggle case all text |
{.shortcuts}
| Shortcut | Description |
|---|---|
<C-o> | Go back to previous |
<C-i> | Go forward |
gf | Go to file in cursor |
ga | Display hex, ascii value |
{.shortcuts}
| - | - |
|---|---|
:h | Help open help view |
:edit! | Reload current file |
:2,8m0 | Move lines 2-8 to 0 |
:noh | Clear search highlights |
:sort | Sort lines |
:ter | Open a terminal window |
:set paste | Enable Insert Paste sub-mode |
:set nopaste | disable Insert Paste sub-mode |
:cq | Exiting with an error<br/>(aborting Git) |
| Shortcut | Description |
|---|---|
% | Nearest/matching {[()]} |
[( | [{ | Previous ( or { |
]) | ]{ | Next ) or } |
[m | Previous method start |
[M | Previous method end |
{.shortcuts}
| Shortcut | Description |
|---|---|
<C-a> | Increase number |
<C-x> | Decrease number |
{.shortcuts}
| 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) |
{.shortcuts}
| - | - |
|---|---|
:ce 8 | Center lines between 8 columns |
:ri 4 | Right-align lines at 4 columns |
:le | Left-align lines |
See :help formatting
| Shortcut | Description |
|---|---|
| <code>`^</code> | Last position of cursor in insert mode |
| <code>`.</code> | Last change in current buffer |
| <code>`"</code> | Last exited current buffer |
| <code>`0</code> | In last file edited |
| <code>''</code> | Back to line in current buffer where jumped from |
| <code>``</code> | Back to position in current buffer where jumped from |
| <code>`[</code> | To beginning of previously changed or yanked text |
| <code>`]</code> | To end of previously changed or yanked text |
| <code>`<</code> | To beginning of last visual selection |
| <code>`></code> | To end of last visual selection |
ma | Mark this cursor position as a |
| <code>`a</code> | Jump to the cursor position a |
'a | Jump to the beginning of the line with position a |
| <code>d'a</code> | Delete from current line to line of mark a |
| <code>d`a</code> | Delete from current position to position of mark a |
| <code>c'a</code> | Change text from current line to line of a |
| <code>y`a</code> | Yank text from current position to position of a |
:marks | List all current marks |
:delm a | Delete mark a |
:delm a-d | Delete marks a, b, c, d |
:delm abc | Delete marks a, b, c |
{.shortcuts}
| Shortcut | Description |
|---|---|
<C-r> = 7*7 | Shows the result |
<C-r> = 10/2 | Shows the result |
{.shortcuts}
Do this in INSERT mode
| - | - |
|---|---|
:!<shell> | Interpret Shell Command |
:r!<shell> | Read in output of shell |
:r!date | Insert date |
:!!date | Replace current line with date |
| 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 |
{.shortcuts}
Remove duplicate lines
:sort | %!uniq -u
To number the lines in the file
:%!cat -n
Copy whole doc to clipboard
:%w !pbcopy # Mac OS X
:%w !xclip -i -sel c # GNU/Linux
:%w !xsel -i -b # GNU/Linux
地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2025 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572