Introduction to common Vi commands and operations

1. Execution and departure of Vi

sherlock@sherlock-laptop:~$ vi #Enter vim to view related commands

2. The operating mode of Vi

 

Command Mode

    Control cursor movement, delete characters, segment copy, and enter Insert Mode or Last Line Mode functions
 

Insert Mode

    The only function is the input of text data. Press Esc to return to Command Mode.
 

Last Line Mode

    Save the file, leave Vi, and other settings. For example, find or replace strings, etc.


 
Vi's mode of operation

i Insert, enter text from the current cursor position

 
a increase, input Chinese characters from the next position of the current cursor
 
o Insert a new line, add a new line and input Chinese characters from the beginning of the line
 
 

Command Mode function key introduction

1. Move the cursor
 

Command Description


h or ← move the cursor one space to the left
j or ↓ Move the cursor down one space
k or ↑ Move the cursor up one space
l or → Move the cursor one space right
Ctrl+B Scroll backward one screen
Ctrl+F Scroll forward one screen
Ctrl+U Scroll half screen backward
Ctrl +D Scroll forward half a screen
Ctrl+E Scroll backward half a line
Ctrl+Y Scroll forward half a line
Number 0 Move the cursor to the beginning of the line
G Move the cursor to the beginning of the last line
W or w Move the cursor to the bottom The prefix of a word e                     Moves
the cursor to the end of the next word
b Moves the cursor to the prefix of the previous word
To the 7th character of the line {cursor moves forward one paragraph } cursor moves backward one paragraph




H Move to the top of the screen
M Move to the middle of the screen
L Move to the bottom of the screen
o Insert a line below the
cursor O Insert a line above the cursor
~ Change letter case
2. Copy text

Command Description

y+y Copy the entire line
y+w Copy a single word Number
+y+y 5+y+y means copy the current cursor position and the following 5 lines together
Number +y+w 5+y+w means copy the current cursor position and the following 5 words together
p Paste Post

3. Delete text

Command Description

d+↑ can delete the line at the cursor position and the previous line at the same time
d+↓ Same as above
d+d deletes the line where the cursor is located. To delete several lines, press the value d key. until all deleted
Number+d+↑ the same way
Number + d + ↓ the same
d+l delete a character

Last Line Mode

Command Description
 
e filename The ":e test" command will create a file named test in the current directory
n filename The ":n test" command will load a file named test in the current Vi window
w Save the current file contents. If this is a new file, the file must be specified            
                    name, such as: ":w test"
q Vi will display an error message if the file is modified
q! Force quit Vi without saving the file
wq save and exit
set nu display line number
set nonu cancels the line number
Entering numbers If you directly enter numbers and then press the Esc key, you can move the cursor to the beginning of the line.
/string This command is used to find a specific string, for example: ":/tcp", if the searched string is not     
                    What you want, you can press the "n" key to continue searching
?string This command is used to find a specific string, for example: ":/tcp", if the searched string is not    
                    What you want, you can press the "n" key to continue searching
 

Replenish

Under GUI:
(1) Press i to enter insert mode
(2) Use the mouse to drag to invert the selection to be pasted, press the left mouse button to copy the selected block to the buffer
(3) Then move the cursor to the place to be pasted, press The middle mouse button (two-button mouse can press the left and right buttons at the same time), paste the buffer content.

In a plain text terminal:
(1) Select a text block, use v to enter visual mode; move the cursor key to select the content
(2) copy the selected block to the buffer, use y; copy the entire line, use yy
(3) Cut the selected block to the buffer, use d; cut the entire line and use dd
(4) to paste the content in the buffer, use p

to open the second file in the same editing window, use :sp [filename]
in multiple editors To switch between files, use Ctrl+w

to add a number in front of the command to indicate the number of repetitions, and add a letter to indicate the buffer name used.
For help, use :help [content or command]

a) Undo the last edit operation. ====> U
b) Repeat the last editing operation. ====》.
c) Revert the undone editing operation. ====> Ctrl + R


For more Vi commands, see Ubuntu Command Tips

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326368563&siteId=291194637