In Linux shell mode, we often need to open files for editing, so it is particularly important to master common vim commands and improve work efficiency. The following is a summary of commonly used vim commands:
1) Big up and small down, that is, capital letters generally face up, and lowercase letters generally face down, such as:
A) o inserts the next row, O: inserts the previous row
B) p (lowercase) means paste after the cursor (bottom), P (uppercase) means paste before the cursor (top)
C) n continue to search (bottom), N reverse search (top)
2) ^ the first $ and the end, simply remember that the dollar depreciates
A)d^: delete to the beginning of the line, d$: delete to the end of the line
B) y^: copy to the beginning of the line (or y0, excluding the character where the cursor is), y$: copy to the end of the line
3) G line w word, that is, g is generally a line or the beginning of the text and the end of the text, and w refers to the character operation
A) dw: delete a word, dG: delete to the end of the text ( g is generally the opposite of the law of big, small, bottom )
B) gg: move to the first line, G: move to the last line
C) yw: copy a word, yG: copy to the end of the text
4) v is visual (visual mode), w is window (window) or word (character), r is replacement, ~ is case
1. The cursor moves under the normal mode:
1) Left and right: Hl
2) Up and down: kj
3) Previous word Next word: bw
2. Enter insert mode
1) i: Insert at the current cursor
2) I: Insert
at the beginning of the line 3) A: Insert at the end of the line
4) o: Insert Next line
5) O: Insert previous line
3. Delete text
1) x: delete a character
2) ndd: delete n lines
3) dw: delete a word
4) d$: delete to end of line
5) d^: delete to
6) dG: delete to the end of the text 7 )
d1G: delete to the beginning of
the
text :set nu Display the line number Example: Insert a new line at the line position - "G+o 5. Copy command 1) yy: copy the entire line where the cursor is located (3yy means copy 3 lines) 2) y^: copy to the beginning of the line, or y0. The character at the cursor position is not included. 3) y$: Copy to the end of the line. Contains the character where the cursor is located. 4) yw: copy one word (y2w: copy two words) 5) yG: copy to the end of the text 6) y1G: copy to the beginning of the text 6. Paste command
1) p (lowercase) means pasting after the cursor (bottom)
2) P (uppercase) means pasting before the cursor (top)
7. Replacement operation
1) r+<letter to be replaced>: replace the letter where the cursor is with the specified
letter2 ) R: continue to replace until Esc is pressed
3) cc: delete the line where the cursor is located, and enter insert mode
4) cw: delete a word and enter insert mode
5) C (uppercase): replace the cursor to the end of the line
6) ~ : Reverse the case of the letter where the cursor is located
8. Undo operation
1) u{n} undoes one or n operations
2) U (uppercase) undoes all modifications to the current row
3) Ctrl+r redo, that is, the undo operation
9. Indent text
1) >> The entire line will be indented to the right
2) << The entire line will fall back to the left
: set sw=10 Set the indent to 10 characters (shiftwidth)
10. Adjust line alignment command
1): ce (center) Center alignment
2): ri (right) content to the right
3): le (left) content to the left
11. Find command (normal mode)
1) / search down
2)? Search up
3) n continue to search
4) N reverse search
5) \* Find the word where the cursor is located
6) \# Same as above to find the word where the cursor is located
7) g\* Same as \*, but part of it matches the word
8) g\# Same as \#, but partially Match the word
: noh Cancel the search
12. Edit multiple files
1) vim 1.txt 2.txt Open multiple files at the same time
2): n! n Edit 2.txt file
3): N! Edit 1.txt file
4 ) :f new.txt Change the current editing file name to new.txt
5) :e# Return to the previous file
13. Visual mode
1) v character selection mode, move the cursor through hjkl
2) shift + v line selection mode
3
) ctrl + v rectangle selection mode
4 ) d delete selection 5) y copy selection To edit 1.txt 3) Ctrl+ws splits the current window into two horizontal windows 4) Ctrl+wv splits the current window into two vertical windows 5) Ctrl+wq That is: q ends the split window. If there is input in the new window, you need to use the mandatory character! ie: q! 6) Ctrl+wo opens a window and hides all previous windows
7) Ctrl+wj move to the lower window
8) Ctrl+wk move to the upper window (j down, h left, l right)