Linux vim commands and linux vim commands
A detailed introduction of vim commands in linux.
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 line on the current screen
M move the cursor to the middle line on the current screen
L move the cursor to the bottom line of the current screen
Bookmarks
Ma stores the current position as tag
'A jump to tag
Edit
R to replace one character
J. Connect the next row to the current row.
Cc deletes the current row and enters the editing mode
Cw deletes the current word and enters the editing mode.
C $ erase the content from the current position to the end of the row and enter the editing mode
S. Delete the current character and enter the editing mode.
S. Delete the row where the cursor is located and enter the editing mode.
Xp exchanges the current and next characters
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
> Move the current row to the right of a unit.
<Shifts the current row to one unit (one tab character) to the left)
= Automatically indent the current row
Insert mode
I enter insert mode from the current cursor
I enters the insert mode, and the cursor is placed at the beginning of the line.
A append mode, after the current cursor
A append mode, with the cursor placed at the end of the row
O Add a new row under the current row and enter the insert mode.
O Add a new row to the current row and enter the insert mode.
Esc exit insert mode
Visual Mode
Mark text
V enters the visual mode, Single Character Mode
V enters the visual mode, and the row Mode
Ctrl + v enter the visual mode, column mode, similar to the column mode of UE
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
Aw select a word
AB Selects all the content in the brackets, including the brackets themselves.
All content in brackets selected by AB
The content in the column selected by ib, excluding the brackets
Content in {} selected by iB, excluding {}
Actions on tags
> Block shifted to the right
<Move left
Y copy Block
D. delete a block.
~ Change the case sensitivity of block content