Some advanced editors will contain macro functions, which are certainly not missing in Vim. It is very convenient to use Macros in VIM:
: QX starts to record macros and saves the results to register x
Q exit record mode
@ X macro commands for playing records in the X register
After you enter QX in normal mode, all the edits to the text will be recorded. If you enter Q again, the record mode will be exited.
And then input @ X to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many Vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command
: Tabe FN: edit the file FN in a new tab
GT switch to the next tab
GT switch to the previous Tab
: Tabr switch to the first tab
: Tabl switch to the last tab
: Tabm [N] Move the current tab to the nth Tab
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
CTRL + w s Horizontal Split Window
CTRL + W switch window
CTRL + w Q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)
CTRL + W v Vertical Split Window
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: W.
: E file: load the file to the new buffer.
: BN jump to the next Buffer
: BD Delete buffer (close file)
: Sp fn split the window and load FN to the new window
Exit Editor
: W write the buffer to a file, that is, save the modification.
: WQ: Save the modification and exit.
: X Save the modification and exit
: Q exits. If the buffer is modified, a message is displayed.
: Q! Force exit, discard Modification
Search and replace
/Pattern: returns the string pattern.
? Pattern: returns the string pattern.
N: Next match (If yes/search, it is the next one ,? Search to the next one)
N match (same as above)
: % S/old/new/g search the entire file and replace all old with new
: % S/old/new/GC search for the entire file, replace all old with new, and each time you want to confirm whether to replace
Copy and paste
Dd deletes the row where the cursor is located.
DW deletes a word)
X Delete the current character
X Delete the previous character
D. Delete it to the end of the row.
YY: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.
Copy one word from YW
Y $ copy to the end of the row
P paste the clipboard content to the current row
P paste the clipboard content to the current row
] P is indented and VIM automatically adjusts it. Code Indent
"A puts the content into/into register a, and supports multiple clipboard
Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ P" command is pasted from the system clipboard to VIM. Note that the "+" operator is not represented here, 21 registers.
Move cursor
In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.
H, J, K, L upper, lower, left, right
CTRL-f.
CTRL-B
% Jump to the brackets matching the current brackets. If the current value is {, the jump is to the matching value }.
W jumps to the next beginning and is separated by punctuation or words.
W jumps to the beginning of the next word and performs a long jump. For example, end-of-line is considered to be a word.
E. Jump to the end of the next word.
E. Jump to the end of the next character, Long Jump
B jumps to the previous word.
B jumps to the previous word, Long Jump
Jump from 0 to the beginning of the line, whether indented or not, that is, jump to 0th characters
^ Jump to the first character of the line
$ Jump to the end of a row
Gg jumps to the first line of the file
GD jumps to the declaration of the variable where the current cursor is located
[N] G jump to the nth line, such as 0g, is equivalent to Gg, 100th G is rows
FX finds x characters in the current row, and jumps
; Repeat the previous F command, instead of repeatedly inputting FX
TX is similar to Fx, but only jumps to the first character of X.
FX and FX are in the opposite direction
), (Jump to the previous or next statement
* Find the word where the cursor is located and look down
# Search for words at the cursor and search up
'. Jump to the previous editing position
Move on screen
H move the cursor to the top row on the current screen
M move the cursor to the middle row on the current screen
l move the cursor to the bottom of the current screen one line
bookmarks
Ma stores the current position as tag a
'a jumps to tag a
edit
r to replace one character
J the next row is connected to the current row.
CC deletes the current row and enters the editing mode.
CW deletes the current word, and enter the editing mode
C $ to erase the content from the current position to the end of the row, and enter edit mode
S to delete the current character and edit mode
S to delete the row where the cursor is located and enter edit mode
XP switches the current character and the next character
U undo
Ctrl + R redo
. repeat the previous edit command
~ Switch case sensitivity. Current Character
G ~ IW switches the case sensitivity of the current word.
guiw converts the current word to uppercase.
guiw converts the current word to lowercase.
shifts the current row to the right.
= automatically indent the current row
insert mode
I enter insert mode from the current cursor
I enter insert mode and move the cursor to the beginning of the line.
A append mode, place the cursor behind the current cursor
A append mode, place the cursor behind the end of the row
O adds a new row under the current row, and enter the insert mode
O adds a new row to the current row, and enter the insertion mode
ESC exit insertion mode
visual mode
flag text
V enter the visual mode, single character mode
V enter the visual mode, row mode
Ctrl + V enter the visual mode, column mode, similar to the UE column mode
o jump cursor to another endpoint of the selected block
U converts the content in the selected block to uppercase
o jump cursor to another endpoint of the block
BR> AW: select a word.
AB: select all the content in brackets, including all the content in the brackets
AB selected {}
IB selected brackets, excluding the content in the brackets
IB selected, not included {}
Actions on tags
> Block shifted to the right
<Move left
Y copy Block
D. delete a block.
~ Change the case sensitivity of block content
Some advanced editors will contain macro functions, which are certainly not missing in Vim. It is very convenient to use Macros in VIM:
: QX starts to record macros and saves the results to register x
Q exit record mode
@ X macro commands for playing records in the X register
After you enter QX in normal mode, all the edits to the text will be recorded. If you enter Q again, the record mode will be exited.
And then input @ X to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many Vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command
: Tabe FN: edit the file FN in a new tab
GT switch to the next tab
GT switch to the previous Tab
: Tabr switch to the first tab
: Tabl switch to the last tab
: Tabm [N] Move the current tab to the nth Tab
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
CTRL + w s Horizontal Split Window
CTRL + W switch window
CTRL + w Q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)
CTRL + W v Vertical Split Window
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: W.
: E file: load the file to the new buffer.
: BN jump to the next Buffer
: BD Delete buffer (close file)
: Sp fn split the window and load FN to the new window
Exit Editor
: W write the buffer to a file, that is, save the modification.
: WQ: Save the modification and exit.
: X Save the modification and exit
: Q exits. If the buffer is modified, a message is displayed.
: Q! Force exit, discard Modification
Search and replace
/Pattern: returns the string pattern.
? Pattern: returns the string pattern.
N: Next match (If yes/search, it is the next one ,? Search to the next one)
N match (same as above)
: % S/old/new/g search the entire file and replace all old with new
: % S/old/new/GC search for the entire file, replace all old with new, and each time you want to confirm whether to replace
Copy and paste
Dd deletes the row where the cursor is located.
DW deletes a word)
X Delete the current character
X Delete the previous character
D. Delete it to the end of the row.
YY: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.
Copy one word from YW
Y $ copy to the end of the row
P paste the clipboard content to the current row
P paste the clipboard content to the current row
] P is indented and VIM automatically adjusts the code indent.
"A puts the content into/into register a, and supports multiple clipboard
Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ P" command is pasted from the system clipboard to VIM. Note that the "+" operator is not represented here, 21 registers.
Move cursor
In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.
H, J, K, L upper, lower, left, right
CTRL-f.
CTRL-B
% Jump to the brackets matching the current brackets. If the current value is {, the jump is to the matching value }.
W jumps to the next beginning and is separated by punctuation or words.
W jumps to the beginning of the next word and performs a long jump. For example, end-of-line is considered to be a word.
E. Jump to the end of the next word.
E. Jump to the end of the next character, Long Jump
B jumps to the previous word.
B jumps to the previous word, Long Jump
Jump from 0 to the beginning of the line, whether indented or not, that is, jump to 0th characters
^ Jump to the first character of the line
$ Jump to the end of a row
Gg jumps to the first line of the file
GD jumps to the declaration of the variable where the current cursor is located
[N] G jump to the nth line, such as 0g, is equivalent to Gg, 100th G is rows
FX finds x characters in the current row, and jumps
; Repeat the previous F command, instead of repeatedly inputting FX
TX is similar to Fx, but only jumps to the first character of X.
FX and FX are in the opposite direction
), (Jump to the previous or next statement
* Find the word where the cursor is located and look down
# Search for words at the cursor and search up
'. Jump to the previous editing position
Move on screen
H move the cursor to the top row on the current screen
M move the cursor to the middle row on the current screen
l move the cursor to the bottom of the current screen one line
bookmarks
Ma stores the current position as tag a
'a jumps to tag a
edit
r to replace one character
J the next row is connected to the current row.
CC deletes the current row and enters the editing mode.
CW deletes the current word, and enter the editing mode
C $ to erase the content from the current position to the end of the row, and enter edit mode
S to delete the current character and edit mode
S to delete the row where the cursor is located and enter edit mode
XP switches the current character and the next character
U undo
Ctrl + R redo
. repeat the previous edit command
~ Switch case sensitivity. Current Character
G ~ IW switches the case sensitivity of the current word.
guiw converts the current word to uppercase.
guiw converts the current word to lowercase.
shifts the current row to the right.
= automatically indent the current row
insert mode
I enter insert mode from the current cursor
I enter insert mode and move the cursor to the beginning of the line.
A append mode, place the cursor behind the current cursor
A append mode, place the cursor behind the end of the row
O adds a new row under the current row, and enter the insert mode
O adds a new row to the current row, and enter the insertion mode
ESC exit insertion mode
visual mode
flag text
V enter the visual mode, single character mode
V enter the visual mode, row mode
Ctrl + V enter the visual mode, column mode, similar to the UE column mode
o jump cursor to another endpoint of the selected block
U converts the content in the selected block to uppercase
o jump cursor to another endpoint of the block
BR> AW: select a word.
AB: select all the content in brackets, including all the content in the brackets
AB selected {}
IB selected brackets, excluding the content in the brackets
IB selected, not included {}
action on the tag
block shifted right
Y copy block
D Delete block
~ Change the case sensitivity of block content