VIM compilation skills

Time:2022-6-11

VIM has three modes to distinguish and pay attention to: insert mode, edit mode and command line mode

PS (when entering VIM, the first thing is editing mode. You can directly use commands to compile content, such as copy and paste)

(in the editing mode, press the keyboard: key to enter the command mode, and then you can type relevant commands after:

(in edit mode, press I or O to enter insert mode)

(1) The following command techniques are all performed in edit mode

1. Jump

The home key jumps to the first character of the current cursor line

End key to jump to the end character of the current cursor line

GG jump to the first character of the first line of the file. This has nothing to do with the cursor position

G jump to the first character of the last line of the file

It can be noted as follows:

The home key and the end key are opposite. One is to jump to the first character of the current mouse, and the other is to jump to the last character of the current mouse

GG and G are opposite. One is to jump to the first character of the first line, and the other is to jump to the first character of the last line

2. Copy / paste / undo

YY copy a line at the cursor

P paste YY the line just copied is pasted on the next line where the cursor is located

YY P is a pair of combinations, which is easy to use and easy to remember

X deletes a single character at the cursor

DD delete a line at the cursor

D^ delete from the cursor to the beginning of the current line

D$delete from cursor to end of current line

C (uppercase) deletes from the cursor to the end of the current line, and enters the input mode. It is the same as d$, but it can be deleted. Instead of entering I, you can directly enter

U undo the last operation

U undo all changes to the current row

CTRL + R undo all previous actions

You can’t stop using all kinds of deletion techniques. What if you delete the wrong one? It doesn’t matter. U will undo your operation. It’s as easy to use as ctrl+z. Whoever uses it will know

3. Find keyword / save

/Hello find all Hello characters in the text and mark them in yellow

n. N jump to the previous and next search results

ZZ save changes and exit

(2) The following is performed in the command mode. In the edit mode, you need to press: on the keyboard, and then enter the command

1. Read the contents of other files to the cursor line

:r  /opt/test. Txt read /opt/test Txt file content to the current cursor line

2. String substitution

: s /123/abc replace the 123 string in the first line of the cursor with ABC

: s /123/abc/g replace all 123 strings in the cursor line with ABC

: S N, MS /123/abc/g replace all 123 strings in the N-M line with ABC

:%s /123/abc replace all 123 strings in the file with ABC

3. Show line number

: set Nu display line number

: set nonu turn off display

last

: WQ save and exit

:q! Forced exit without saving

Recommended Today

A front-end developer's Vim is the same as an IDE

Here is my new configurationjaywcjlove/vim-webI've been grinding it, and it's basically ready to use. Take it out and cheat the star Install The latest version of Vim 7.4+ uses (brew install macvim) installation, vim version updatebrew install macvim –override-system-vim View configuration locations # Enter vim and enter the following characters :echo $MYVIMRC download vim-web Download […]