Summary of practical operation of vim work

1. How to undo in vim

u Undo the operation of the previous step
Ctrl+r Restore the operation of the previous step that was undone

2. Select all, single selection copy and paste

Delete all: After pressing esc, press gg (to get to the top), then dG
Copy all: After pressing esc, press gg, then ggyG
Select all Highlight: After pressing esc, press gg, then ggvG or ggVG
paste :p

Single line copy: press esc key, then yy
single line delete: press esc key, then dd

3. Cutting

d is basically similar to the y command, so the usage of the two commands is the same, including the usage of numbers.
d cuts the selected block to the buffer;
dd cuts the entire line
d^ cuts to the beginning of the line
d$ cuts to the end of the line
dw Cut a word
dG cut to the end of the file

4. View mode

Select text block
1). Use v to enter visual mode, and move the cursor key to select the content.

    2). 选定文件中全部文本块ggVG

5. Cursor movement

n space (n is a number): Press the number n and then press the space, the cursor will move n characters to the right, if the number of characters in this line is less than n, the cursor will continue to move from the next line to the right until the n number 0
or Home: move to the beginning of the current line
$ or End: move to the end of the current line
H: move the cursor to the top line of the current screen
M: move the cursor to the central line of the current screen
L: move the cursor to the bottom of the current screen Line
G: Move the cursor to the last line of the text
nC: (n is a number) Move the cursor to the nth line of the text
gg: Move the cursor to the first line of the text
n Enter (n is a number): Move the cursor down n lines

Six, vim search

1. In the normal mode, press the slash/+ the content to be inquired and press Enter
2. Press n to search down, press N to search up
3. Exit the highlight and enter the command mode: nohl

Seven, vim global replacement command

Steps:
To perform global replacement in vim, you can use :scommands. The specific operations are as follows:

  1. Open the file to be replaced and enter vim editing mode.
  2. To enter command mode, press the colon (:) key.
  3. Input s/要替换的内容/替换后的内容/g, which srepresents a replace command, grepresents a global replace.
  4. Press the Enter key, and vim will automatically perform the replacement operation.
例子:
:s/apple/orange/g   #apple:表示替换的内容,orange表示替换后的内容,/g表示全局替换

8. Matters needing attention

The problem that vim can only paste 50 lines:
edit ~/.vimrc in the current user's home directory (if it does not exist, create a new file), add a line

:set viminfo='1000,<500

Guess you like

Origin blog.csdn.net/wei1359765074410/article/details/125333355