当前位置:网站首页>Summary of common commands of vim
Summary of common commands of vim
2022-06-26 09:29:00 【Great white bear_ BlankBear】


Use... On the current line in the command state == ( Continuous press = two ), Or for multiple lines n==(n It's a natural number ) Indicates auto indent below the current line n That's ok . You can try to indent the code and scramble it n== Typesetting , It's equivalent to IDE Inside code format. Use gg=G The whole code can be typeset .
vim Select text , Delete , Copy , Paste
The choice of text , For editors , It's very basic , And it's often used , Summarized below :
v From the current position of the cursor , Where the cursor passes will be selected , Then click on the v end .
V Start with the current line of the cursor , The lines that the cursor passes through will be selected , Then click on the V end .
Ctrl + v From the current position of the cursor , Select the rectangular area formed by the start and end of the cursor , Then click on the Ctrl + v end .
ggVG Check all the text , among gg To jump to the beginning of the line ,V Select the whole line ,G At the end of
After selecting it, you can edit it with the edit command , Such as
d Delete
y Copy ( The default is copy to " register )
p Paste ( The default from the " Register take out content paste )
"+y Copy to system clipboard ( That is to say vim Of + register )
"+p Paste from the system clipboard
=============================================================
vim Command summary
1. Delete character
To delete a character , Just move the cursor over the character and press "x".
2. Delete a line
Delete a whole line and use "dd" command . After deletion, the next line will move up to fill in the vacancy .
3. Remove line breaks
stay Vim You can merge two lines into one , That is to say, the newline between the two lines has been deleted : The order is "J".
4. revoke
If you delete too much by mistake . Obviously you can type it again , But orders "u" Easier , It can undo the last operation .
5. redo
If you undo it many times , You can still use it CTRL-R( redo ) To reverse the undo action . let me put it another way , It's an undo of undo . There's another form of undo ,"U" command , It undoes all operations on one line at a time . A second use of the command undoes the previous "U" The operation of . use "u" and CTRL-R You can retrieve any operation state .
6. Additional
"i" The command inserts text before the current cursor .
"a" The command inserts text after the current cursor .
"o" The command can start a new line below the current line , And change the current mode to Insert Pattern .
"O" command ( Notice the capital letters O) Will start a new line above the current line .
7. Use the command count
Suppose you want to move up 9 That's ok . It works "kkkkkkkkk" or "9k" To complete . in fact , Many commands can accept a number as the number of times to repeat the same command . Take the example just now , Add three exclamation marks at the end of the line , The order was "a!!!". Another way is to use "3a!" command .3 The command will be repeated 3 Time . Again , Delete 3 Two characters can be used "3x". The specified number should be immediately before the command it is going to modify .
8. sign out
To exit Vim, Command "ZZ". This command saves the current file and exits Vim.
9. Give up editing
Discard all changes and exit , Command ":q!". use ":e!" Command to discard all changes and reload the original contents of the file .
10. With Word For the movement of units
Use "w" The command moves the cursor forward one word On the first character of ; such as "3w" Move the cursor forward 3 individual words."b" The command moves the cursor back to the previous word On the first character of .
"e" The command moves the cursor to the next word Last character of . command "ge", It moves the cursor to the previous word On the last character of .、
11. Move to the beginning or end of a line
"$" Command to move the cursor to the end of the current line . If you have a key on your keyboard , It works the same way ."^" Command to move the cursor over the first non blank character on the current line ."0" The command always moves the cursor to the first character of the current line . So is the bond ."$" The command can also accept a count , Such as "1$" Will move the cursor to the end of the current line ,"2$" Will move to the end of the next line , And so on ."0" The command does not accept counts like this , command "^" Adding a count before it doesn't have any effect .
12. Move to the specified character
command "fx" Find the next character on the current line x( To the right ), Can count with a command "F" Command search left ."tx" Orders are like "fx" command , It's just that it doesn't stop the cursor on the searched character , It's a character before it . Tips :"t" Meaning for "To". The reverse version of the command is "Tx". this 4 Any command can be used ";" To repeat . With "," And repeat the same command , But the direction is the opposite of the original command .
13. Move... To match a bracket
Command "%" Jump to the bracket that matches the bracket under the current cursor . If the current cursor is in "(" On , It jumps forward to match it ")" On , If it's in ")" On , It automatically jumps back to the matching "(" Up .
14. Move to specified row
use "G" Command specifies a command count , This command positions the cursor on the line specified by the command count . such as "33G" Will put the cursor on the second 33 Go ahead . If the command count is not specified as a parameter , "G" Will position the cursor on the last line ."gg" Commands are a quick way to jump to the first line .
Another way to move to a line is in the command "%" Before specifying a command count, for example "50%" The cursor will be positioned in the middle of the file . "90%" Jump near the end of the file .
command "H","M","L", Jump the cursor to the first line respectively , Middle row , At the end of the line .
15. Tell you where you are
Use CTRL-G command ."set number" Display a line number in front of each line . Instead, close the line number with the command ":set nonumber".":set ruler" stay Vim The lower right corner of the window shows the current cursor position .
16. Scroll
CTRL-U The window that displays the text scrolls up half the screen .CTRL-D Command to move the window down half screen . Scrolling one line at a time can use CTRL-E( Scroll up ) and CTRL-Y( Scroll down ). To scroll a whole screen forward, use the command CTRL-F. in addition CTRL-B It's the reverse version of it ."zz" The command will center the current line on the screen ,"zt" The command places the current line at the top of the screen ,"zb" Put the current line at the bottom of the screen .
17. Simple search
"/string" The command can be used to search for a string . To find the next position of the last searched string , Use "n" command . If you know exactly where you're looking for is the number of occurrences of the target string , You can also do it in "n" Put a command count before ."3n" Will look up the second... Of the target string 3 time .
"?" Command and "/" It's the same job , It's just that the search is in the opposite direction ."N" The command repeats the previous search , But with the original "/" or "?" The specified search direction is opposite .
If the search ignores case , Use the command "set ignorecase", Return the exact match with the command "set noignorecase" .
18. Find the next... In the text word
Put the cursor on this word Go up and press "*" key .Vim Will take the current cursor word And use it to search the target string ."#" The order is "*" The reverse version of . You can also add a command count before these two commands :"3*" Find... Under the current cursor word For the third time .
19. Find the whole word
If you use "/the" Search for Vim It will also match "there". To find... As a separate word "the" Use the following command :"/the\>"."\>" It's a special notation , It only matches one word At the end of . Approximately ,"\<" Match to a word At the beginning of . So look up as a word Of "the" You can use it :"/\".
20. Highlight search results
Turn on this function with ":set hlsearch", Turn this off :":set nohlsearch". If you just want to remove the current highlight , You can use the following command :":nohlsearch"( I could just write it as noh).
21. Match the beginning and end of a line
^ Characters match the beginning of a line .$ Characters match the end of a line .
therefore "/was$" Match only words at the end of a line was, therefore "/^was" Match only words at the beginning of a line was.
22. Match any single character
. This character can match any character . such as "c.m" Can match any previous character is c, The last character is m The situation of , No matter what the middle character is .
23. Match special character
Put a backslash before the special character . If you look up "ter.", Command "/ter\."
24. Use the tag
When you use "G" When an order jumps from one place to another ,Vim I'll remember where you took off . This position is Vim It's a marker in . Use command " `` " It can make you jump back to the starting point .
`` Commands can jump back and forth between two points .CTRL-O The command is to jump to where you stopped the cursor earlier ( Tips :O Meaning for older). CTRL-I It is to jump back to the updated position of the stop cursor ( Tips :I On the keyboard, located in O front ).
notes : Use CTRL-I Just like pressing a key .
25. A nametag
command "ma" Name the position under the current cursor as a marker "a". from a To z A total of 26 A custom tag . To jump to a marker you've defined , Use command " `marks "marks It's the name of the defined tag . command " 'a " Make you jump to a The beginning of the line ," `a " It'll pinpoint a Where it is . command :":marks" Used to view a list of tags .
command delm! Delete all tags .
26. Operator commands and displacements
"dw" The command can delete a word,"d4w" The command is to delete 4 individual word, And so on . Similar to "d2e"、"d$". There is a fixed pattern for such commands : Operator commands + Displacement command . First, type an operator command . such as "d" It's a delete operator . And then there's a life shift . such as "w". So any move cursor command goes to , It's all within the scope of the command .
27. Change the text
The operator command is "c", Change the order . Its behavior and "d" Command similar , But after the command is executed, it will enter Insert Pattern . such as "cw" Change one word. perhaps , More precisely , It removes one word And put you in Insert Pattern .
"cc" Commands can change the whole line . However, the original indent is maintained .
"c$" Change the current cursor to the end of the line .
Quick orders :x representative dl( Delete the character under the current cursor )
X representative dh( Delete the character to the left of the current cursor )
D representative d$( Delete to the end of the line )
C representative c$( Change to the end of the line )
s representative cl( Change a character )
S representative cc( Modify a whole line )
command "3dw" and "d3w" It's all deletions 3 individual word. The first order "3dw" It can be seen as deleting a word The operation of 3 Time ; Second command "d3w" It's a deletion 3 individual word. That's not the obvious difference . In fact, you can put an order in both places to count , such as ,"3d2w" Is to delete two word, repeat 3 Time , The total is 6 individual word.
28. Replace single characters
"r" Command is not an operator command . It waits for you to type the next character to replace the character under the current cursor ."r" A command count before a command is to replace multiple characters with the character to be entered . To replace a character with a newline character, use "r". It will delete a character and insert a newline character . Using command counting here will only delete the specified number of characters :"4r" Will put 4 Replace characters with a newline character .
29. Repeat the changes
"." The command repeats the last change ."." The command will repeat all the changes you make , except "u" command CTRL-R And commands that start with a colon ."." Need to be in Normal Execution in mode , It repeats the command , It's not something that's been changed ,
30.Visual Pattern
Press "v" Can enter the Visual Pattern . Move the cursor to cover the range of text you want to manipulate . At the same time, the selected text will be highlighted . Finally, type the operator command .
31. Mobile text
With "d" or "x" When such a command removes text , The deleted content is still saved . You can still use it p Order it back ."P" The command is to put the returned content in front of the cursor ,"p" It's behind the cursor . In the "dd" Delete the entire line ,"P" It will be placed on the previous line of the current line ."p" As for the next line of the current line . You can also command "p" and "P" Commands use commands to count . The effect is that the same content is retrieved a specified number of times . thus "dd" After that "3p" You can delete the line of 3 Put copies in the current location .
command "xp" Swap the character of the cursor with the next character .
32. Copy text (VIM Copy in editor )
"y" The operator command copies the text to a register 3 in . And then you can use "p" Order it back . because "y" It's an operator command , So you can use "yw" To make a copy of word. You can also use the command to count . In the following example "y2w" Command to copy two word,"yy" Command to copy a whole line ,"Y" It's also copying the entire line , The command to copy the current cursor to the end of a line is "y$".
33. Text object
"diw" Delete... Where the current cursor is word( Not including white space ) "daw" Delete... Where the current cursor is word( Include white space characters )
34. Quick orders
x Delete the character under the current cursor ("dl" Quick commands for )
X Delete the character before the current cursor ("dh" Quick commands for )
D Delete the content from the current cursor to the end of the line ("d$" Quick commands for )
dw Delete from current cursor to next word The beginning of
db Delete from current cursor to previous word The beginning of
diw Delete... Where the current cursor is word( Not including white space )
daw Delete... Where the current cursor is word( Include white space characters )
dG Delete the current line to the end of the file
dgg Delete the contents of the current line to the file header
If you use "c" Command instead of "d" These commands become change commands . Use "y" Namely yank command , And so on .
35. Edit another file
Command ":edit foo.txt", It can also be abbreviated as ":e foo.txt".
36. File list
Can be started at Vim To edit multiple files , Command "vim one.c two.c three.c".Vim Only the first file will be displayed after startup , After editing the file , You can use the order :":next" or ":n" To save the work and continue editing the next file , command :":wnext" or ":wn" You can merge this process .
37. Displays the file currently being edited
Command ":args".
38. Move to another file
Command ":previous" ":prev" Back to the last file , The merge and save steps are ":wprevious" ":wprev". To move to the last file ":last", To the first ":first". But no ":wlast" perhaps ":wfirst" Such an order . Can be in ":next" and ":previous" The command is preceded by a command count .
39. Edit another file list
No reboot Vim, You can redefine a list of files . command ":args five.c six.c seven.h" Defines three files to edit .
39. Auto save
command ":set autowrite","set aw". Automatically write the content back to the file : If the file has been modified , At every :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] and CTRL-^ On command .
command ":set autowriteall","set awa". and 'autowrite' similar , But it also applies to ":edit"、":enew"、":quit"、":qall"、":exit"、":xit"、":recover" On and off Vim window . Setting this option also means Vim It's like opening 'autowrite' equally .
40. Switch to another file
To quickly switch between two files , Use CTRL-^.
41. File tags
A mark named after a capital letter . They are global markers , They can be used in any file . such as , Editing "fab1.Java", Command "50%mF" In the middle of the file, set a file named F The tag . And then in "fab2.java" In file , Command "GnB" On the last line, set the name B The tag . When available "F" The command jumps to the file "fab1.java" In the middle of the half . Or edit another file ,"'B" The order will bring you back to the file "fab2.java" Last line .
To know what position a marker represents , You can use the name of the tag as "marks" Arguments to the command ":marks M" Or keep up with several parameters in succession ":marks MJK"
It can be used CTRL-O and CTRL-I You can jump to an earlier position and a later position .
42. see file
Just looking at the file , Don't write to the file , You can edit files as read-only . Command :
vim -R file. If you want to avoid mandatory changes to the file , You can use the command :
vim -M file.
43. Change file name
Save an existing file as a new one , Command ":sav(eas) move.c". If you want to change the name of the file you are currently editing , But don't want to save the file , You can use the command :":f(ile) move.c".
44. Split a window
The easiest way to open a new window is to use the command :":split".CTRL-W Command can switch the current active window .
45. close window
Command :"close". You can close the current window . actually , Any command to exit file editing ":quit" and "ZZ" Will close the window , But with ":close" It can stop you from closing the last one Vim, So as not to accidentally shut down the whole Vim.
46. Close all windows except the current one
Command :":only", Close all windows except the current one . If any of these windows have been modified , You get an error message , And that window will be left .
47. Separate a window for another file
command ":split two.c" You can open a second window and start editing in the newly opened window as
Parameter file . If you want to open a new window and start editing an empty buffer , Use command :":new".
48. Vertical segmentation
Command ":vsplit or ::vsplit two.c". There is also a corresponding ":vnew" command , Used to vertically separate windows and open a new empty buffer in them .
49. Switch windows
CTRL-W h Go to the window on the left
CTRL-W j Go to the window below
CTRL-W k Go to the upper window
CTRL-W l Go to the window on the right
CTRL-W t To the top window
CTRL-W b The bottom window
50. Commands for all window operations
":qall" Give up all operations and exit ,":wall" Save all ,":wqall" Save all and exit .
51. Open a window for each file
Use "-o" Options allow Vim Open a window for each file :
"vim -o one.txt two.txt three.txt".
52. Use vimdiff View different
"vimdiff main.c~ main.c", Another way to enter diff The way to model can be in Vim In operation . Edit the file "main.c", Then open another separate window to show its different values :
":edit main.c"
":vertical diffpatch main.c.diff".
53. Tab
command ":tabe(dit) thatfile" Open in a window "thatfile", The window occupies the entire Vim Display area . command ":tab split/new" The result is a new tab with one window . For "gt" The command switches between different tabs .
In this paper, from : http://fableking.iteye.com/blog/1141518
---------------------------------------------------------------------------------------------------------
Here are some of the basic usages I've summarized , It may be helpful for new users , It is much joyful to share the joy than enjoy alone. , Is that so? !
explain : The black below is vi and vim All have the same general functions , And red is Vim(Vi Improved) The unique function of .Vim General Unix and Linux It's all installed under .
Three states
Command: Any input will be used as an edit command , Not on the screen , Any input causes an immediate response
Insert: Any input data is placed in the edit register , Press ESC, You can jump back to command The way
Escape: With “:” perhaps “/” For leading instructions , Appears on the bottom line of the screen , Any input is treated as a special instruction .
Leave vi
:q! Leave vi, And discard what you just edited in the buffer .
:wq Write the data in buffer to disk , And leave vi.
:x Same as wq.
( Be careful —— :X It's file encryption , Be sure to make contact with :x Save and exit )
Enter input mode
a (append) Add data after cursor .
A Add information from the end of the bank .
i (insert) Add data before cursor .
I Add information from the head of the bank .
o (open) Add a new line below it for data input .
O Add a new line to this line for data input .
Delete and modify
x Delete the character where the cursor is located .
X Delete the word before the cursor .
r Replace... With the character following this instruction (replace) The character of the cursor . Such as :ra Change the character of the cursor to a Instead of .
R Into a state of substitution , until 《ESC》 until .
s Delete the character of the cursor , And enter input mode until 《ESC》.
S Delete the row where the cursor is located , And enter input mode until 《ESC》.
Cursor movement
m<a-z> Bookmark <a-z>
‘<a-z> Move to bookmark <a-z> It's about
0 Move to the top of the line
$ Move to the end of the line .
e Move to the last letter of the next word
w Move to the first letter of the next word .
b Move to the first letter of the previous word .
^ Move to the first character of the line .
H Move to the first line of the window .
M Move to the middle line of the window .
L Move to the last line of the window .
G Move to the last line of the file .
+ Move to the first character in the next column .
- Move to the first character in the previous column .
:n Move to page n Column .
n+ Move to the next... After the cursor position n Column .
n- Move to the second... Before the cursor n Column .
<Ctrl><g> Displays the line number of the line 、 File name 、 The last line number in the file 、 The percentage of cursor row number in total row number .
(Vim) Basic usage of cursor movement :
( This can be understood by combining the functions above , No need to explain it again !)
ge b w e
← ← ---→ --→
This is-a line, with special/separated/words (and some more).
←- ←-- -----------------→ ---→
GE B W E
The movement of windows
<Ctrl><f> The window scrolls down one page .
<Ctrl><b> The window scrolls up one page .
<Ctrl><d> The window scrolls down half a page .
<Ctrl><u> Window up half page .
<Ctrl><e> The window scrolls down one line .
<Ctrl><y> The window scrolls up one line .
shear 、 Copy 、 Delete
Operator + Scope = command
Operator
d shear
y Copy .
p Sticky stick , And d and y Match and use . But in the end d or y The data of is placed under the row and column where the cursor is located .
c modify , similar delete And insert Group and . Delete a word group 、 Sentences, etc , And insert the new data .
Scope
e From the cursor position to the last character of the string .
w From the cursor position to the first character of the next string .
b From the cursor position to the first character of the previous string .
$ From the cursor position to the last character of the line .
0 From the cursor position to the first character of the line .
The whole line
dd Delete entire line .
D Behavior unit , Delete all characters after cursor .
cc Modify the entire line .
yy Copy the cursor to the memory buffer .
Cancel the previous action (Undo)
u Restore the result before the last instruction .
U Restores all changes to the row of the cursor .
(vim) u You can undo instructions many times , Undo one action at a time , Until the beginning of this operation .
(vim) Ctrl+r You can restore what you did before undoing , Press multiple to recover multiple times .
Find and replace
/ String Look after the cursor for the string .
? String Look for the string before the cursor .
n Go on to find the next same string .
N Go up and look for the next same string .
% lookup “(”,“)”,“{”,“}” The matchmaker of .
s Search for a range .
g Search the entire edit buffer .
:1,$s/old/new/g Put all the 『old』 Change to 『new』.
:10,20s/^/ / Will be the first 10 To the first 20 Insert... At the front of the row data 5 Blank .
(vim)
/ character string The input query content can be saved in the buffer , You can use ↑↓ Select the past content .
in addition : Move the cursor under the selected word and press *, You can select this word as the query character , The trouble of inputting a long string of characters can be avoided .
(vim) Case substitution
First, press v Enable selection function , And then use ↑↓←→ Key to select the character you want to replace , If you change lowercase to uppercase , Then press U; On the contrary, press u;
If it's choosing words , You can press v after , Press w, Finally according to the U/u, In this way, you can change the case of characters at will , Instead of deleting and typing again .
Data connection
J The connection of sentences . Connect the line below the cursor to the back of that line of the cursor .
The setting of the environment
:set all List of environment variables that can be set
:set The current value of the environment variable
:set nu Set the line number of the data .
:set nonu Cancel line number setting .
:set ai Auto shrink .
:set noai Cancel auto shrink .
(vim)
:set ruler The current cursor position will be displayed in the lower right corner of the screen , And it changes as the light moves , Less screen space , Easy to use , Recommended .
:set hlsearch When using the find function , All matches are highlighted .
:set nohlsearch Turn off this function .
:set incsearch send Vim In the process of entering a string , The cursor can locate and display the matching point .
:set nowrapscan Turn off the auto loopback function , Find the end of the file , Find the end ; The default state is auto loopback
ex Instructions
Reading and writing materials
:10,20w test Will be the first 10 To the first 20 Row data is written to test file .
:10,20w>>test Will be the first 10 To the first 20 The information of the row is added to test After the document .
:r test take test The data of the file is read to the end of the edit buffer .
:e [filename] Edit a new file .
:e! [filename] Discard the currently modified file , Edit a new file .
:sh Get into shell Environmental Science , Use exit sign out , Back in the editor .
:!cmd Run the command cmd after , Return to the editor .
Delete 、 Copy and move
:10,20d Delete the first 10 To the first 20 Information on the line .
:10d Delete the first 10 Information on the line .
:%d Delete the entire edit buffer .
:10,20co30 Will be the first 10 To the first 20 Copy the data of row to 30 After line .
:10,20mo30 Will be the first 10 To the first 20 The data of row is moved to 30 After line .
边栏推荐
- 挖财打新债安全吗
- Collection object replication
- "One week's work on Analog Electronics" - Basic amplification circuit
- 【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)
- "One week to finish the model electricity" - 55 timer
- The most complete and simple nanny tutorial: deep learning environment configuration anaconda+pychart+cuda+cudnn+tensorflow+pytorch
- 我在中山,到哪里开户比较好?在线开户安全么?
- Yolov5 results Txt visualization
- Error importerror: numpy core. multiarray failed to import
- 計算領域高質量科技期刊分級目錄
猜你喜欢

Detectron2 outputs validation loss during training

How to solve the sample imbalance problem in machine learning?

"One week's work on Analog Electronics" - power amplifier

《一周学习模电》-电容、三极管、场效应管

CVPR:Refining Pseudo Labels with Clustering Consensus over Generations for Unsupervised Object Re-ID

工企专利匹配数据(数十万数据量)1998-2014年

Pycharm occasionally encounters low disk space

GAN Inversion: A Survey
![[pulsar learning] pulsar Architecture Principle](/img/ec/5ab9aabc2beafd4238dc8055ba6fb2.png)
[pulsar learning] pulsar Architecture Principle
QPM performance monitoring components - General
随机推荐
Nacos registry structure and the principle of massive service registration and concurrent read-write source code analysis
Real time data analysis tool
《一周搞定数电》-逻辑门
进入页面输入框自动获取焦点
【pulsar学习】pulsar架构原理
Kubernetes cluster deployment (v1.23.5)
jz2440---使用uboot烧录程序
Solve Django's if Version (1, 3, 3): raise improverlyconfigured ('mysqlclient 1.3.3 or new is required
Self learning neural network series - 7 feedforward neural network pre knowledge
《单片机原理及应用》——概述
"One week's work on Analog Electronics" - optocoupler and other components
Cancellation and unbinding of qiniu cloud account
Jetson TX2 installing the SciPy Library
MySQL单表500万条数据增、删、改、查速度测试
Introduction to QPM
首期Techo Day腾讯技术开放日,628等你
《單片機原理及應用》——概述
Statistics of various target quantities of annotations (XML annotation format)
Creation and use of XSync synchronization script (taking debian10 cluster as an example)
Spark based distributed parallel processing optimization strategy - Merrill Lynch data