Vi common commands

1. About vi

vi is the most powerful text editor, not one of them. Although vi is already an antique-level software, there are still countless newcomers who face difficulties to learn, which shows its classic and popular degree.

Whether it's in a novel or a TV series, truly powerful weapons are not easy to control. It takes some effort to gain more powerful power, especially for vi, an ancient artifact . Because it uses the keyboard throughout, many
people who are exposed to vi for the first time feel uncomfortable and give up halfway. However, friends who stick to it will gradually find that the design of this keyboard operation is superb. The reason why a classic can become a classic must have its truth. There is no need to explain too much.

Observing the proficiency of a programmer with vi, we can judge its technical level. If he is not familiar with vi, he is definitely not a programmer under the Linux platform. People who say that vi is not good for use must also be unfamiliar with vi and Linux. No exception.

2. Create/Open File

vi 文件名

   
    
    
  • 1

Open a file, if the file does not exist, create it.

Example:

vi book.c

   
    
    
  • 1

Three, the three modes of vi

vi
has three modes, command line mode, insert mode and replacement mode. In command line mode, any keyboard input is a command, and in insert mode and replacement mode, the keyboard input is only characters.

Insert mode and replace mode are also called edit mode together.

Four, vi-like regular commands

Esc Switch from editing mode to command line mode.

i Insert before the cursor position.

a Start inserting after the cursor position.

o Insert a blank line below the line at the cursor position.

O Insert a blank line above the line at the cursor position.

I Insert at the beginning of the line at the cursor position.

A Insert at the end of the line at the cursor position.

k is similar to the arrow keys.

j is similar to the arrow keys.

h is similar to the left arrow key.

Type l is the right arrow key.

Ctrl+u turn up half a page.

Ctrl+d Page down.

nG The cursor jumps to the beginning of the nth line of the file.

G The cursor jumps to the last line of the file.

:5 Enter the cursor to jump to the fifth line.

:n Enter the cursor to jump to the nth line.

0 The cursor jumps to the beginning of the current line.

$ The cursor jumps to the end of the current line.

w The cursor jumps to the beginning of the next word.

b The cursor jumps to the beginning of the previous word.

e The cursor jumps to the end of this word.

Each press of x deletes a character at the cursor position.

nx such as "3x" means to delete 3 characters from the cursor position.

dw Delete the characters from the cursor position to the end of the word.

D Delete all the content behind the cursor position in this line.

dd Delete the line at the cursor position.

ndd such as "3dd" means to delete 3 lines from the cursor position.

yy copies a line at the cursor position to the buffer.

nyy copies the n lines at the cursor position to the buffer.

p Paste the content in the buffer to the cursor position.

r Replace a character at the cursor position.

R Start replacement from the cursor position until "Esc" is pressed.

cw Replace the word from the cursor position until "Esc" is pressed.

u The cancellation order can be cancelled multiple times.

J Connect the next line of the current line to the end of the current line.

Ctrl+g displays the line number at the cursor position and the total number of lines in the file.

/abcd Search for "abcd" text content in the currently opened file.

n Find the next one.

N Find the previous one.

. Repeat the last executed vi command.

~ Perform case conversion on the character at the current position of the cursor.

Column operation

Ctrl+V uppercase or lowercase I input content Esc

:w Enter to save.

:w! Press Enter to force save.

:wq Enter to save and exit.

:x Enter to save and exit.

:q Enter and exit without saving.

:q! Press Enter to force exit without saving.

:g/aaaaaaaaa/s//bbbbbb/g Enter to replace all aaaaaaaaa in the file with bbbbbb.

Ctl+insert copy the text selected by the mouse, equivalent to Ctl+c.

Shift+insert outputs the text selected by the mouse, which is equivalent to Ctl+v.

The above two commands are common in windows and UNIX.

1. About vi

vi is the most powerful text editor, not one of them. Although vi is already an antique-level software, there are still countless newcomers who face difficulties to learn, which shows its classic and popular degree.

Whether it's in a novel or a TV series, truly powerful weapons are not easy to control. It takes some effort to gain more powerful power, especially for vi, an ancient artifact . Because it uses the keyboard throughout, many
people who are exposed to vi for the first time feel uncomfortable and give up halfway. However, friends who stick to it will gradually find that the design of this keyboard operation is superb. The reason why a classic can become a classic must have its truth. There is no need to explain too much.

Observing the proficiency of a programmer with vi, we can judge its technical level. If he is not familiar with vi, he is definitely not a programmer under the Linux platform. People who say that vi is not good for use must also be unfamiliar with vi and Linux. No exception.

2. Create/Open File

vi 文件名

   
  
  
  • 1

Open a file, if the file does not exist, create it.

Example:

vi book.c

   
  
  
  • 1

Three, the three modes of vi

vi
has three modes, command line mode, insert mode and replacement mode. In command line mode, any keyboard input is a command, and in insert mode and replacement mode, the keyboard input is only characters.

Insert mode and replace mode are also called edit mode together.

Four, vi-like regular commands

Esc Switch from editing mode to command line mode.

i Insert before the cursor position.

a Start inserting after the cursor position.

o Insert a blank line below the line at the cursor position.

O Insert a blank line above the line at the cursor position.

I Insert at the beginning of the line at the cursor position.

A Insert at the end of the line at the cursor position.

k is similar to the arrow keys.

j is similar to the arrow keys.

h is similar to the left arrow key.

Type l is the right arrow key.

Ctrl+u turn up half a page.

Ctrl+d Page down.

nG The cursor jumps to the beginning of the nth line of the file.

G The cursor jumps to the last line of the file.

:5 Enter the cursor to jump to the fifth line.

:n Enter the cursor to jump to the nth line.

0 The cursor jumps to the beginning of the current line.

$ The cursor jumps to the end of the current line.

w The cursor jumps to the beginning of the next word.

b The cursor jumps to the beginning of the previous word.

e The cursor jumps to the end of this word.

Each press of x deletes a character at the cursor position.

nx such as "3x" means to delete 3 characters from the cursor position.

dw Delete the characters from the cursor position to the end of the word.

D Delete all the content behind the cursor position in this line.

dd Delete the line at the cursor position.

ndd such as "3dd" means to delete 3 lines from the cursor position.

yy copies a line at the cursor position to the buffer.

nyy copies the n lines at the cursor position to the buffer.

p Paste the content in the buffer to the cursor position.

r Replace a character at the cursor position.

R Start replacement from the cursor position until "Esc" is pressed.

cw Replace the word from the cursor position until "Esc" is pressed.

u The cancellation order can be cancelled multiple times.

J Connect the next line of the current line to the end of the current line.

Ctrl+g displays the line number at the cursor position and the total number of lines in the file.

/abcd Search for "abcd" text content in the currently opened file.

n Find the next one.

N Find the previous one.

. Repeat the last executed vi command.

~ Perform case conversion on the character at the current position of the cursor.

Column operation

Ctrl+V uppercase or lowercase I input content Esc

:w Enter to save.

:w! Press Enter to force save.

:wq Enter to save and exit.

:x Enter to save and exit.

:q Enter and exit without saving.

:q! Press Enter to force exit without saving.

:g/aaaaaaaaa/s//bbbbbb/g Enter to replace all aaaaaaaaa in the file with bbbbbb.

Ctl+insert copy the text selected by the mouse, equivalent to Ctl+c.

Shift+insert outputs the text selected by the mouse, which is equivalent to Ctl+v.

The above two commands are common in windows and UNIX.

Guess you like

Origin blog.csdn.net/qq_43403759/article/details/108364703