当前位置:网站首页>(no plug-in) summary of vim basic shortcut keys
(no plug-in) summary of vim basic shortcut keys
2022-06-13 01:42:00 【lainegates】
List of articles
First two pictures , Then give the text description . The first one , Composite diagram .
Cursor movement illustration :

The shortcut key defaults to Normal Pattern , Press <ESC> After the state of the .<c-*> representative Ctrl+*
1. see
1.1 Foundation movement
| Key | effect |
|---|---|
h/j/k/l | Left , Next , On , Right |
w/e/b | The beginning of the next word / The end of the next word / The beginning of the last word |
W/E/B | ( Separated by spaces ) The beginning of the next word / The end of the next word / The beginning of the last word |
</> | visual Pattern Select to indent |
1.2 Flip screen 、 Jump
| Key | effect |
|---|---|
% | In pairs {}/[]/() Jump between |
H/M/L | Jump to the top of the current screen 、 In the middle 、 Bottom |
#L | Jump to the... Of the current screen # That's ok |
zt/zz/zb | The current edit line is set to Screen top / In screen / Bottom of screen |
gg/G | Jump to the file's start / Bottom |
(/) | Jump to the beginning of the current line 、 At the end of the line |
{ /} | Up 、 Jump down to the nearest empty line |
[{ /}] | Jump to the current block start 、 ending |
0/$/^ | Jump to Head of line / The first non blank character of the line / At the end of the line ,#$ You can skip to the... After this line # The end of line No |
:#/#G | Jump to the first # That's ok |
<c-b> / <c-f> | towards front / after One page , The first key combination is Ctrl+b |
<c-u> /<c-d> | towards front / after Half page |
<c-e>/ | towards Next / On Get out of here |
1.3 choice
| Key | effect |
|---|---|
V | Choose a line |
<c-v> | Rectangle selection |
v3w | Select three characters from the cursor , among v For from Normal Mode entry Visual Pattern |
2. edit
2.1 newly added
| Key | effect |
|---|---|
i/I | In front of the cursor / At the beginning of the current line Insert |
a/A | After the cursor / At the end of the current line Insert |
o/O | After the current line / Before you go Insert |
:r filename | Insert... In the current position filename Content |
:r! command | Insert... In the current position stay shell perform command Result , Such as :r! date Insert time at current position |
2.2 modify c(change)
| Key | effect |
|---|---|
r/R | Modify the characters under the cursor / Modify the character where the cursor goes ( Equivalent to pressing Insert key ) |
cw/c#w/C | Change the word at the cursor to the end / modify # Characters / Modify to the end of the line |
ci'/ di'/yi'/vi' | modify / Delete / Copy / Choose ` Match text content in punctuation marks |
s/#S | Delete the character at the current cursor / Delete # That's ok , Then enter Insert Pattern |
2.3 Delete d(delete)
| Key | effect |
|---|---|
#x/#X | Cut cursor On the right / On the left n Characters , amount to d[n]l/d#h |
D/d$/d^ | Delete to At the end of the line / At the end of the line / Head of line |
dw/daw/d#w | Delete The word ends at the cursor / The word ends at the cursor ( Including spaces after words )/ Delete # Word |
#dd | Delete the line starting from the cursor # That's ok |
diB/daB | Delete {} The content in / Delete {} And its contents |
:m,n d | take m-n Cut the contents between lines to the pasteboard |
dgg/dG | Cut the cursor to On / Next All right |
2.4 lookup f(ind)
| Key | effect |
|---|---|
f‘n’/F'n' | Jump behind the cursor first / the previous character ’n’ ( coordination ;/,, positive / Reverse repeat lookup ) |
t‘n’/T'n' | Jump behind the cursor first / the previous character ’n’ Before ( coordination ;/,, positive / Reverse repeat lookup ) |
//? | towards after / front Search for keywords , Then you can match n/N towards after / front Find the next keyword |
*/# | Take the word where the cursor is located as the keyword , towards after / front Search for the next keyword |
2.5 Copy y(yank)
| Key | effect |
|---|---|
yw/#yw | Copy to the current ending / The copy cursor starts # Word |
Y/yy/#yy | Copy the current row / Copy the current row / Copy from the current line # That's ok |
p | Paste |
:m,ny | Copy the current file m-n The content of the line |
ygg/yG | Copy the cursor to On / Next All right |
yaw/yas | Copy a word and a sentence , It doesn't matter if the cursor is not at the beginning of the word or sentence , among a representative around |
2.6 Replace r(place)
grammar { Range }s/{ Matching mode }/{ Target string }/{ Options }
Range: Refers to the effective scope%: Represents the entire documentn1,n2: Representative only inn1 To n2Effective between lines.: Current row ,{ Range }Use this case when null0: The first line ( It could be that ).$: The last line
s: fingersubstitue, ReplaceMatching mode: forcharacter stringorRegular expressionsTarget string: String to replace withOptions:- Common items
g/c/n, Represent theoverall situation/The replacement should be determined/( Do not replace ) Only the number of matches is counted - It's empty , Only the first matching item is replaced
- Common items
2.7 toggle case u(ppercase)
| Key | effect |
|---|---|
~ | toggle case |
u/U | Visual In mode , Change the selected character to A lowercase letter / Capitalization |
g[u|U]{ Range } | take Range The characters in are changed to A lowercase letter / Capitalization , See table below |
g[u|U]{ Range } Example :
gUU/guu: Change the letter of the current line toCapitalization/A lowercase lettergUw/guw: Change the word under the current cursor toCapitalization/A lowercase lettergU$/gu$: Change the words at the end of the line toCapitalization/A lowercase letter
2.8 Undo and redo (normal Pattern )
| Key | effect |
|---|---|
[#]u | Cancel # A change |
:undo 5 | revoke 5 A change |
:undolist | Your revocation history |
<c-r> | Redo the last changes |
U | Cancel all changes in the current line |
:earlier 4m | go back to 4 Minutes ago |
:later 55s | Forward 55 second |
3. Programming AIDS
3.1 Basic keys
| Key | effect |
|---|---|
gd/gD | Jump to Local / overall situation Where the variable is defined , When searching for global variables, start searching from the beginning of the current file |
K | Display the help document of the function where the current cursor is located in a new window |
g;/g, | the previous / next Where it has been modified |
[[/[] | Jump to the previous function block Start / end , Need a separate line of { |
]]/][ | Jump to the next function block Start / end , Need a separate line of { |
[{ /]} | Jump to the current block Start / end |
[//]/ | Jump to the current comment block Start / end |
% | Not only can you move to the matching (),{} or [] On , And can be in #if,#else, #endif Jump between |
3.2 ctags
ctags -R: Generate tag file ,-R Indicates that it is also generated for files in subdirectories tags
| Key | effect |
|---|---|
:set tags=path/tags | tell ctags Which one to use tag file |
:tag xyz | Jump to the xyz Where is the definition of , Or place the cursor on xyz Press up C-], For return C-t |
:stag xyz | Display... In a split window xyz The definition of , perhaps C-w ], If you use C-w n ], It'll open a n Row high window |
:ptag xyz | Open... In the preview window xyz The definition of , Hotkeys are C-w } |
:pclose | Close preview window . Hotkeys are C-w z |
:pedit abc.h | Edit... In the preview window abc.h |
:psearch abc | Search the current file and the current file include The file of , Display contains abc The line of |
Sometimes one tag There may be multiple matches , Such as function overload , A function name will have multiple matches . In this case, you will jump to the first match .
| Key | effect |
|---|---|
:[#]tnext | Next [#] A match . |
:[#]tprev | Last one [#] A match . |
:tfirst | The first match |
:tlast | The last match |
:tselect tagname | Open the selection list |
tab Key completion
| Key | effect |
|---|---|
:tag xyz<tab> | Complete with xyz At the beginning tag name , Continue to press tab key , Other... Will be displayed |
:tag /xyz<tab> | Can use a name that contains xyz Of tag Name complement |
3.3 cscope
cscope -Rbq: Generate cscope.out file
| Key | effect |
|---|---|
:cs add {/path/to/cscope.out} {/your/work/dir} | |
:cs find c {func} | Lookup function func Where is called |
:cw | open quickfix Window view results |
3.4 gtags
Gtags A combination of ctags and cscope The function of . Use Gtags Before , You need to install GNU Gtags. Then run... In the project directory gtags .
| Key | effect |
|---|---|
:Gtags {funcname} | Locate the funcname Where is the definition of . |
:Gtags -r {funcname} | Inquire about funcname Where it's quoted . |
:Gtags -s {symbol} | location symbol Where it appears . |
:Gtags -g {string} | Goto string Where it appears . :Gtags -gi string Ignore case . |
:Gtags -f {filename} | Show filename List of functions in . You can use it. :Gtags -f % Show current file . |
:Gtags -P {pattern} | Show files with a specific schema in the path . Such as :Gtags -P .h$ Show all header files , :Gtags -P /vm/ Show vm A file in a directory . |
3.5 compile
vim Provides :make To compile the program , The default call is make, If you have... In your current directory makefile, simply :make that will do .
If you don't make Program , You can configure makeprg Options to change make Called program . If you have only one abc.java file , You can set :
set makeprg=javac\ abc.java
then :make that will do . If the program is wrong , Can pass quickfix Window view error . But if you want to locate the error correctly , It needs to be set up errorformat, Give Way vim Identify error messages . Such as :
:setl efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
- %f For file name
- %l Indicates line number
- %m Indicates an error message
Others don't understand , Please refer to :help errorformat
3.6 Quick modify window
It's actually quickfix The functions provided by plug-ins , It is very useful for compiling debugging programs
| Key | effect |
|---|---|
:copen | Open the quick modify window |
:cclose | Close the quick modify window |
Quick modify window in make It is very useful when using the program , When make after :
| Key | effect |
|---|---|
:cl | List errors in the quick fix window |
:cn | Go to the next error |
:cp | Navigate to the previous error |
:cr | Locate the first error |
3.7 Automatic completion
| Key | effect |
|---|---|
<c-x> <c-s> | Spelling suggestions |
<c-x> <c-v> | completion vim Options and orders |
<c-x> <c-l> | Complete the whole line |
<c-x> <c-f> | Auto complete file path . After the pop-up menu , Press C-f Cycle selection , Of course, you can also press <c-p> and <c-n> |
<c-x> <c-p>/<c-x> <c-n> | Complete the current word with the words that appear in the document . Directly by <c-p> and <c-n> It's fine too |
<c-x> <c-o> | When programming, you can complete keywords and function names , Need to install vim plug-in unit |
<c-x> <c-i> | Complete according to the keywords in the header file |
<c-x> <c-d> | Complete the macro definition |
When the completion menu pops up :
| Key | effect |
|---|---|
<c-p> /`` | forward / backward Switch members |
C-e | Exit the drop-down menu , And return to the original text |
C-y | Exit the drop-down menu , And accept the current option |
3.8 Multiline indent out
Normal In mode , Press two >, The line where the cursor is located will be indented .
If you press math first n, Press twice more >, Below the cursor n Guild indent .
Corresponding , Press two <, The line where the cursor is located will shrink out .
stay Visual In mode , Select the code block to adjust , Press =, The code will be indented according to the writing rules .
perhaps n =, adjustment n Line code format .
3.9 Fold
| Key | effect |
|---|---|
zf/a/p | Command to create a fold , You can use this command on a visual area |
zd/zD | Deletes the collapse of the current row |
zfap | Collapse the segment where the cursor is located |
zo | Open collapsed text |
zc | Stow and fold |
za | open / Close the current fold |
zr | Open nested line breaks |
zm | Collapse nested line breaks |
zR/zO | Open all line breaks |
zM /zC | Put away all folding lines |
zj/zk | Jump to the Next / On A fold |
zi | Turn on / close Folding function |
4. vim General advanced editing functions
4.1 Text block
Summary text block usage a representative around,i representative in
| Key | effect |
|---|---|
aw/iw | A word ( contain / Not included Left and right symbols ) |
as/is | A word of , Space off ( contain / Not included Left and right space ) |
ap | a section , Separate with blank lines |
ab | A piece of ( Enclosed in parentheses ) |
y/d/c/v Can be combined with text objects
for example :
ci’, di’, yi’: modify 、 Cut or copy ’ Content between .
ca’, da’, ya’: modify 、 Cut or copy ’ Content between , contain ’.
ci", di", yi": modify 、 Cut or copy " Content between .
ca", da", ya": modify 、 Cut or copy " Content between , contain ".
ci(, di(, yi(: modify 、 Cut or copy () Content between .
ca(, da(, ya(: modify 、 Cut or copy () Content between , contain ().
ci[, di[, yi[: modify 、 Cut or copy [] Content between .
ca[, da[, ya[: modify 、 Cut or copy [] Content between , contain [].
ci{, di{, yi{: modify 、 Cut or copy {} Content between .
ca{, da{, ya{: modify 、 Cut or copy {} Content between , contain {}.
ci<, di<, yi<: modify 、 Cut or copy <> Content between .
ca<, da<, ya<: modify 、 Cut or copy <> Content between , contain <>.
4.2 Bookmarks (bookmark)、 Mark
| Key | effect |
|---|---|
m{a-z} | Mark the position of the cursor , Local markers , Only for the current file , There can be 26 Mark positions |
m{A-Z} | Mark the position of the cursor , Global marker . After marking , sign out Vim, Restart , The tag is still valid |
| `{a-z} | Move to the mark position |
'{a-z} | Move to the beginning of the tag line |
| `` | Jump back and forth between the current editing position and the last editing position |
<c-i>/<c-o> | Jump to the Historical location / Update location , Infinite backtracking |
:marks | Show all tags |
:delmarks a c-f/:delmarks! | Delete tag a、c、d、e、f / Delete all tags |
4.3 register register
Deposit operation with " start , stay Normal In mode , With "{ Register name }{ operation } The format uses registers .
Registers can be used to hold code fragments .
| Register description | effect |
|---|---|
a-z | Can be used as register names ."ayy Put the contents of the current line into a register |
A-Z | Index registers with uppercase letters , You can append content to the register . Such as "Ayy Append the contents of the current line to a In the register |
:reg | Display the contents of all registers |
"" | Without register index , Register used by default |
"* | The current selection buffer ,"*yy Put the contents of the current line into the current selection buffer |
"+ | System clipboard ."+yy Put the contents of the current line into the system clipboard |
4.4 macro macro
| Key | effect |
|---|---|
. | Normal In mode , Repeat the previous edit action |
q{a-z} | Start recording macros , The number is a letter a-z One of |
q | Stop recording |
@{a-z | The playback number is {a-z} macro |
5. Multi file operation
5.1 Multi file basic operation
vi a.txt b.txt c.txt
Multi file operation is mostly used in command mode
| command | effect |
|---|---|
:#n[ext] | Editor # File |
:previous/:N | Edit last file |
:wnext | Save the current file , And edit the next file |
:wprevious | Save the current file , And edit the previous file |
:args | Show file list |
:n filenames/:args filenames | Specify a new file list |
vi -o filenames | Edit multiple files in multiple windows divided horizontally (vim External shell Command line ) |
vi -O filenames | Edit multiple files in multiple windows divided vertically (vim External shell Command line ) |
:wq filename | Save your edits to a file filename, And exit |
:e/:e!/:e filename | Reload the current file / Reload the current file and discard the changes / Open file filename |
:f filename/:saveas filename | Save as filename |
e#/<c-^> | Go back to the last edited file |
:f/<c-g> | Display the current file name in the status bar |
5.2 Multi label operation ( Rarely used )
| command | effect |
|---|---|
vim -p files | Open multiple files , Each file occupies a tab |
:tabe/tabnew | If you add a file name , Just open this file in a new tab , Otherwise, open an empty buffer |
:tabn/Control + PageDown | Switch to the next tab |
:tabp/Control + PageUp | Switch to the previous tab |
[#]gt | Switch to the next tab . If you add #, Just switch to the # A label . The serial number starts with 1 |
:tab split | Open the contents of the current buffer in a new tab |
:tabc[lose] | Close the current tab |
:tabo[nly] | Close other tabs |
:tabs | List all tabs and the windows they contain |
:tabm[ove] [N] | Move tabs , Move to N After two tabs . Such as tabm 0 The current tab , It will become the first tab |
5.3 buffer
A buffer holds an open file
| command | effect |
|---|---|
:buffers/:ls/:files | Displays a list of buffers |
ctrl+^ | Switch between the last two buffers |
:bn | Next buffer |
:bp | Previous buffer |
:bl | The last buffer |
:b[n]/:[n]b | Switch to n Buffers |
:nbw[ipeout] | Delete article... Completely n Buffers |
:nbd[elete] | Delete the first n Buffers , Did not really delete , still unlisted In the list |
:ba[ll] | Open all buffers in the current page , Each buffer occupies one window |
6. Window operation
| command | effect |
|---|---|
vim -o file1 file2 | Split the window horizontally , Open at the same time file1 and file2 |
vim -O file1 file2 | Split the window vertically , Open at the same time file1 and file2 |
6.1 Horizontal segmentation
| command | effect |
|---|---|
:sp[lit]/<c-w> s/ <c-w> <c-s> | Divide the current window horizontally into two windows . Be careful ,<c-s> The terminal may freeze , Please press <c-q> continue |
:sp[lit] filename | Split the window horizontally , And display another file in a new window |
:[#]sp[lit] | Split one horizontally # Row high window |
:[#]new/<c-w> n/<c-w> <c-n> | Split one horizontally # Row high window , And edit a new file . |
ctrl+w f | Split a window horizontally , And open the file named the word where the cursor is located in a new window |
6.2 Vertical segmentation
| command | effect |
|---|---|
:vs[plit]/ v | /<c-w> <c-v> Divide the current window into two horizontally distributed windows |
:[#]vne[w] | A vertical partition with a height of # The new window of |
:vertical | Horizontal split command : Corresponding vertical segmentation |
6.3 Close subwindow
| command | effect |
|---|---|
:wq/ZZ/:x | Save your edits , And exit ,w(write) Write ,q(uit) sign out , |
q! | ! Force operation ( Such as q! Exit without saving ) |
:qall | Close all windows , sign out vim |
:wall | Save all modified windows , namely write all |
:only/<c-w> o | Keep only the current window , Close other windows .(CTRL-W o) |
<c-w>q/:q/:close/<c-w> c | Close the current window , Do not save |
6.4 Resize window
| command | effect |
|---|---|
<c-w> +/<c-w> - | current window Increase / Reduce a line . It can also be used. n Increase n That's ok |
<c-w> _/ctrl+w | | The current window expands as large as possible / The current window expands as wide as possible , Be similar _/| Represent the That's ok / Column |
<c-w> #/:resize n/n <c-w> _ | Set the window to # Row height |
<c-w> = | All windows have the same height |
[#]<c-w> </[#]<c-w> > | current window Reduce / increase # Column |
6.5 Switch and move windows
| command | effect |
|---|---|
<c-w> w/<c-w> <c-w> | Switch to the next window |
<c-w> p | Switch to the previous window |
<c-w> h/l/j/k | Switch to Left / Right / Next / On The window of |
<c-w> t/b | Switch to At the top / At the bottom Face window |
<c-w> H/L/K/J | Move the current window to Leftmost left / Right / On / Next |
<c-w> r | Rotate the position of the window |
<c-w> T | Move the current window to a new tab |
6.6 Adjust the font
| command | effect |
|---|---|
<c-->/<c-=> | Font tone Small / Big |
7. Command line
normal Press in mode : Enter command line mode
7.1 Shortcut keys in command line mode
| command | effect |
|---|---|
Up and down direction key | Previous or next command . If you have entered some commands , Then find a Or the next matching command |
Left right key | Left / One character to the right |
<c-w>/<c-h> | Delete a forward word / character , The latter is equivalent to Backspace |
<c-u> | Move from the current position to the beginning of the command line |
<c-b>/<c-e> | Move to the command line start / ending |
Shift-Left>/Shift-Right> | Left / Right Move a word |
@: | Repeat the last colon command |
q: | Normal mode ,q Then press ’:’, Open the command line history buffer , You can edit commands just as you edit files |
q//q? | You can open the search history |
7.2 Execute external command
| command | effect |
|---|---|
:!{command} | Execute external command command |
:!! | Execute the last external command |
:sh {bash-file} | from shell call {bash-file}, use exit return vim |
:r !cmd | Insert the returned result of the command into the current location of the file , Such as r! echo % Returns the current file name |
:m,nw !cmd | The m Row to n The contents between lines are used as command input to execute the command |
8. Other
8.1 working directory
| command | effect |
|---|---|
:pwd | Show vim Working directory of |
| :cd path ` | change vim Working directory of |
| :set autochdir ` | It can make vim Automatically switch the working directory according to the edited file |
8.2 Some shortcuts
| command | effect |
|---|---|
K | Open the word where the cursor is located manpage |
g <c-g> | Count the number of words in the full text or part of the statistics |
8.3 Online Help
| command | effect |
|---|---|
:h(elp) or <F1> | Open general help |
:help user-manual | Open the user manual |
The format of the command help is : The first line indicates how to use that command ; Then there is an indented paragraph explaining the function of this command , Then there is further information .
| command | effect |
|---|---|
:helptags somepath | by somepath Generate index for documents in |
:helpgrep | You can search the entire help document , The list of matches is displayed in quickfix Window |
Ctrl+] | Jump to tag The theme ,Ctrl+t Jump back |
:ver | Display version information |
8.4 Some small functions
Simple calculator : In insert mode , Input C-r =, Then enter the expression , You can be in Get the calculation result at the cursor .
9. Typesetting
Less use of typesetting , So put it in the back position
9.1 Basic typesetting
| Key | effect |
|---|---|
<</>> | towards Left / Right Indent one shiftwidth |
:ce(nter)/:le(ft)/:ri(ght) | This line of text In the middle / Keep to the left / Keep right |
gq | Rearrange the selected text , That is to break long text |
gq#j | Rearrange the current line and below # That's ok |
gq#q | rearrangement # That's ok ,# If it is blank, only the current line |
gq#ap | rearrangement # paragraph ,# If it is blank, only the current segment |
gqQ | Rearrange the current paragraph to the end of the article |
J/gJ | Splice the current line and the next line , The latter does not save spaces |
9.2 Spelling check
| Key | effect |
|---|---|
:set spell/:set nospell | Turn on / close Spell check function |
]s/[s | Move to next / the previous Misspelled words |
z= | Displays a list of misspelled words , You can choose from |
zg | Tell the spelling checker that the word is spelled correctly |
zw | Contrary to the previous command , Tell the spelling checker that the word is misspelled |
Reference resources
边栏推荐
- [wsl2] restrict wsl2 accessible hardware resources (cpu/ memory)
- 他山之石:a16z 的 Web3 投资版图
- 受众群体应该选择观察模式还是定位模式?
- 深度学习调参技巧详解
- Add default right-click menu
- 如何利用您的自有数据来实现营销目标?
- [Stanford Jiwang cs144 project] lab1: streamreassembler
- Leetcode question brushing 03 stack
- Auto commit attribute of MySQL
- 关于tkinter.Canvas 不显示图片的问题
猜你喜欢

Create a simple game interface using pyGame

DFS and BFS notes (II): depth first search (implemented in C language)

Implementation and design of JMeter interface test database assertion for CSDN salary increase technology

The storage structure of a tree can adopt the parent representation, that is, the parent pointer array representation. Try to give the corresponding class definition. Each tree node contains two membe

leetcode743. 网络延迟时间(中等, dijkstra)

Introduction to ROS runtime

Simple operation of MySQL database

【斯坦福計網CS144項目】Lab1: StreamReassembler

5、 Improvement of inventory query function

Startup, connection and stop of MySQL service
随机推荐
Torch. Distributions. Normal
Cmake has no obvious error after compilation, but prompts that pthread cannot be found
Tweets movement description and chart display
开发者来稿|AMD赛灵思中文论坛分享 - 提问的智慧
MySQL related summary
Phaser3 load
Create a simple game interface using pyGame
Stm32 3*3 matrix key (register version)
谷歌的受众群体是如何发挥作用的?
Set and array conversion, list, array
机器学习基础 SVM(支持向量机)
Simple operation of MySQL database
Unity jsonutility failed to serialize list
Idea installation tutorial
TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
MySQL ---- where后使用字段别名
水管工游戏
Jeux de plombiers
csdn涨薪技术之Jmeter接口测试数据库断言的实现与设计
Database query user mailbox