linux - the most commonly used operation of vim

1. Open the file

 

vim + #: open the file, and locate at line #

 

vim +: open the file and navigate to the last line

 

vim +/PATTERN: Open the file and navigate to the beginning of the line matched by PATTERN for the first time

 

2. Close the file

 

:q quit

 

:wq save and exit equals :x equals zz in edit mode

 

:q! Force quit without saving

 

:w save

 

:w! force save

 

Three, mode conversion

 

Edit Mode -> Input Mode

 

i: In front of the character where the current cursor is, switch to input mode

 

a: After the character where the current cursor is located, switch to input mode

 

o: Create a new line below the current cursor line and switch to input mode

 

I: At the beginning of the line where the current cursor is located, switch to input mode

 

A: At the end of the line where the current cursor is located, switch to input mode

 

O: Above the line where the current cursor is located, create a new line and switch to input mode

 

Input Mode -> Edit Mode

 

ESC

 

Edit Mode -> Last Line Mode

 

 

Last Line Mode -> Edit Mode

 

ESC

 

Edit Mode -> Visual Mode

 

v In visual mode, you can freely select from the cursor position, and then delete, copy and other operations on the selected content

 

4. Move the cursor (edit mode)

 

1. Move character by character

 

h, j, k, l: left, down, up, right

 

2. Move by word

 

w: skip to the beginning of the next word

 

e: skip to the end of the current or next word

 

b: skip to the beginning of the current or previous word

 

3. Inline jump

 

0: absolute line start

 

^: the first non-whitespace character at the beginning of the line

 

$: absolute line ending

 

4. Jump between lines

 

#G: Jump to line # is equal to the last line mode: # Just give the line number directly

 

G: Jump to the last line is equal to the last line mode: $

 

Five, flip the screen

 

ctrl + d: scroll down half screen

 

ctrl + u: scroll up half screen

 

ctrl + f: scroll up one screen

 

ctrl + b: scroll down one screen

 

6. Delete

 

1. Delete a single character

 

x: delete the single character where the cursor is

 

2. The d command is used in combination with the jump command

 

dw, de, db delete a word after/before the current cursor

 

dd: delete the line where the current cursor is located

 

#dd: delete # lines including the line where the current cursor is located

 

7. Copy and paste

 

1. Copy y usage is the same as d command

 

2. Paste p or P

 

8. Replacement

 

r #: replace the current character with #

 

R: replace pattern

 

9. Undo editing

 

u: undo the previous editing operation, continuous u command can be undone all the way forward

 

ctrl + r : undo the last undo

 

10. Repeat the previous editing operation

 

Eleven, find and replace

 

/PATTERN: Search for PATTERN from the beginning of the cursor to the end of the file

 

?PATTERN: Search for PATTERN from the beginning of the cursor to the beginning of the file

 

n: Repeat the last search command in the same direction

 

N: Repeat the last search command in the reverse direction

 

:s/p1/p2/g replace all p1 with p2 in the current line

 

:n1,n2s/p1/p2/g replace all p1 in lines n1 to n2 with p2

 

:%s/p1/p2/g replace all p1 in the file with p2

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326854994&siteId=291194637