Master the key VIm command to resolve the bug, change the configuration file, check the log, explain %99 embarrassing disease!
I want to insert (normal –> insert mode) :
- I: Insert the cursor at the beginning of the line
- A: Start at the next position where the cursor is currently located
- A: Insert at the end of the line where the cursor is
- O: Insert a line under the cursor
- O: Insert a line on the cursor
Two, repeated horizontal jump (move cursor in normal mode) :
- Ctrl+ F: Scroll down one page
- H: Move the cursor left
- L: Move the cursor right
- J: Move the cursor down
- K: Move the cursor up
- Ctrl+ B: Move one page up
- Ctrl+ E: Scroll down
- Ctrl+ Y: Scroll up
- G: Move to the top line of the file
- Gg: moves to the end of the file line, equivalent to 1 GB
- H moves to the top line of the screen
- M moves the cursor to the middle row of the screen
- L Move the cursor to the bottom line of the screen
- 0: moves to the top of the line
- $: moves to the end of the line
- W: The cursor jumps to the beginning of the next word
- E: The cursor jumps to the end of the next word
- B: The cursor goes back to the beginning of the last word
Find and Replace (command mode)
- /Ame: Looks down for a string named Ame. N, find the next n, find the last one
- ? Ame: Looks up a string named Ame. N, n
- :n1,n2s/Ame/FlyFly/g: Look for this string between lines n1 and n2 and replace it with FlyFly.
- $s/Ame/FlyFly/g: look for the string Ame and replace it with FlyFly.
- The same goes for % s/Ame/FlyFly/g
- :1,$s/Ame/FlyFly/gc: prompt user when replacing
Iv. Delete, Copy and paste:
- X, x: In a line of text, x is to delete one character backward (equivalent to the [Del] key), x is to delete one character forward (equivalent to [Backspace])
- Dd: Deletes the entire line where the cursor is
- Dw: Deletes the previous word
- D $: Deletes the cursor to the end of the line
- NDD: deletes n rows down where the cursor is
- Yy: Copies the line where the cursor is located
- Nyy: Copies the cursor n rows down
- P, p: p indicates that the copied content is pasted to the cursor. P indicates that the copied content is pasted to the line above the cursor
- U: Undo operation
- Ctrl+ R: Redo the previous action. (Can be used to reverse undo)
- R: Replaces a character at the cursor position
- R: Replaces the characters around the cursor until “ESC” is pressed
- J The current line joins the next line
Full text delete: Press ESC, then gg (to top), then dG
Full text copy: Press ESC, then gg, then yG
V. In command mode:
- Set nu: lists the row number
- Set nonu: Unlists line numbers
- Set IC: Ignore case when searching
- Set noic: Desist from ignoring case in search
- N: Jumps to a line in the file. N indicates a number. For example, enter the number 15 and press Enter to jump to the 15th line
- ! PWD: Run the shell command PWD
Visual mode
- Character mode V (lowercase)
- Copy, delete and paste. After selecting the highlighted text, the operation is the same as normal mode
- Modification. Select the highlighted text and press C to delete and enter insert mode
- Line mode V (uppercase)
- The indentation. Hold down the > and < keys to move the code block to the right or left.
- Copy, delete and paste. After selecting the highlighted text, the operation is the same as normal mode
- Block mode Ctrl + V
- The indentation. Same as above
- Copy, delete and paste. After selecting the highlighted text, the operation is the same as normal mode
Application in visual mode:
-
Copy, delete and paste. After selecting the highlighted text, the operation is the same as normal mode
-
Modification. Select the highlighted text and press C to delete and enter insert mode
-
The indentation. Hold down the > and < keys to move the code block to the right or left.
-
Case conversion. Press U to capitalize the selected content – press U to write the selected content smaller – press ~ to flip the size.
-
Add (remove comments), often used for configuration file management.
(1) Add batch annotations. CTRL + V to enter block mode, move the cursor down or up to mark the beginning of the line you want to comment, then press uppercase I(Shift + I), insert a comment character such as “#”, and press Esc twice to comment it all.
(2) Batch remove comments. CTRL + V to enter block mode, horizontally select the number of columns (such as the “#” comment symbol) and press D to remove the comment symbol.
Seven, code block application
- % jumps to the matching parentheses
- > increase indentation
- < reduce indentation
- {skip to the beginning of the previous paragraph
- } Skip to the beginning of the next paragraph
- Move to the beginning of the sentence
- ) Move to the beginning of the next sentence
- Ctrl+] jumps to function, variable definition
- Ctrl+ O returns to the jump position
- “Jump to the last place the cursor docked, two, not one.”
Master key VIm commands:
- Bookmark this article
- Install the Vim plugin on your existing editor
- Practice! Practice! Practice!
Feel free to point out any shortcomings in the comments section.
Favorites, likes and questions are welcome. Follow the top water cooler managers and do something other than pipe hot water.