Commonly used commands of the vi editor in Linux system: linuxvi
Vi is a text editor in Linux. Beginners may be troubled by a large number of commands. Here, I have screened some common commands for your reference.
Common commands for accessing vi:
Vi filename: open or create a file and place the cursor at the beginning of the first line
Vi + filename: open the file and place the cursor at the beginning of the last line
I. Common commands for inserting text
Command description
I... insert text before the current character
I... insert text at the beginning of the row
A... add text after the current character
A... add text at the end of the row
O... insert an empty row behind the current row
O... insert an empty row before the current row
R · input text in rewriting Mode
2. Common commands for moving the cursor
Command description
J or down arrow... move a row down.
K or the up arrow... move a row up.
H or left arrow... move one character to the left
L or right arrow... move one character to the right
W · shift one word right
W · shift right of a word separated by Spaces
B · move a word left
B · move left a word separated by Spaces
0... moved to the beginning of the line
Ctrl F... flip the page forward
Ctrl B · flip back
NG · to line n
G · to the last line
3. Common commands for replacing text
Command description
$ To the end of the line
At the beginning of a sentence
) To the end of a sentence
Before the beginning of a paragraph
} To the end of the paragraph
4. Common commands for deleting texts
Command description
R · replace a character
C. Modify the text until you Press Esc.
Cw modify the next word
Cnw rename the next n words
5. Save and exit Common commands
Command description
Zz · Save and quit
: W filename · writing files
: W · writing files
: X · Save (if the previous file has been modified) and exit
: Q! · Do not save the file and exit directly
: Q... exit vi.