The VIM command, as the most used text editor in Linux, is very powerful and contains various commands for manipulating text. This article collects the most commonly used VIM commands in Linux Systems/VI command Daquan.
vim Command Daquan
cursor control commands:
Command cursor movement
H move one character to the left
J Move down one line
K Move up one line
L Move one character to the right
G move to the last line of the file
W moves to the beginning of the next word
W moves to the beginning of the next word, ignoring punctuation
b move to the beginning of the previous word
B move to the beginning of the previous word, ignoring punctuation
L move to the last line of the screen
M moves to the middle line of the screen
H moves to the first line of the screen
E moves to the end of the next word
E moves to the end of the next word, ignoring punctuation
(move to the beginning of the sentence
Move to the end of the sentence
{Move to the beginning of a paragraph
Move to the beginning of the next paragraph
0 (number), | Move to the first column of the current row
^ Move to the first non-null character of the current line
$ move to the last character of the current line
+, Enter moves to the first character of the next line
-Move to the first non-empty character of the previous line
to add text in VI:
Command Insert Action
A inserts text after the cursor
A inserts text in the current line
I insert text before the cursor
I insert text before the current line
o Insert a new row below the current line
O Insert a new row at the top of the current row
s removes the character at the cursor and enters insert mode
S Delete the line where the cursor is located and enter insert mode
: R file reads the file contents and inserts it into the current line
: Nr file reads files into document contents, and then inserts on Nth line
ESC Back to command mode
^v Char when inserted ignores the specified meaning of char, this is to insert special characters
Delete the text in VI:
Command Delete operation
X Delete the character at the cursor
DW Delete to the beginning of the next word
DG deletes the line until the end of the file
DD Delete entire row
DB Delete the word in front of the cursor
: N,MD Delete n rows from line m
D, d$ Delete from cursor to end of line
^H, backspace when inserting, remove the preceding character
^w when inserting, delete the preceding word
Modify VI Text:
The number in front of each command indicates the number of times the command was repeated
Command substitution operations
Rchar replacing the current character with Char
R text escape replaces the current character with text until the ESC key is pressed
Stext Escape uses text instead of the current character
S or Cctext escape with text instead of whole line
Cwtext Escape Change the current word to text
Ctext escape changes the remainder of the current line to text
CG escape modified to the end of the file
Ccursor_cmd text escape changes from the current position to the cursor command position to text
Find and Replace in VI:
Command Lookup and replace operations
/text finding text forward in a file
? text looks backwards in the file for text
N repeated lookups in the same direction
N repeated lookups in the opposite direction
Ftext find text in current line forward
Ftext find text backward in current line
Ttext finds text in the current line and positions the cursor in the first character of text
Ttext the text in the current row, and positions the cursor in the first character of text
: Ignore case when set IC lookup
: Set Noic is case sensitive when looking for
: ranges/pat1/pat2/g replace OldText with NewText
: M,ns/oldtext/newtext in M line through N, replace with NewText OldText
& Repeat Last: s command
: G/text1/s/text2/text3 find rows containing Text1, replace with Text3 Text2
: G/text/command command to run on all lines that contain text
: V/text/command command to run on all lines that do not contain text
Copy the text in VI:
Command copy operation
YY puts the contents of the current row into a temporary buffer
Nyy the contents of n rows into a temporary buffer
P puts the text in the temporary buffer after the cursor
P put the text in the temporary buffer before the cursor
"(A-Z) NYY copy n rows into a named buffer with a name of parentheses, omitting N to indicate when the forward
"(A-Z) NDD deletes n rows into a named buffer with the name parentheses, omitting N to indicate when the forward
"(A-Z) p puts the contents of a named buffer with parentheses in the current line
"(A-Z) P put the contents of a named buffer with parentheses in front of the current line
Undo and Redo in VI:
Command undo Action
U Undo Last Modification
U Undo all modifications to the current line
. Repeat last Modification
To repeat the previous F, F, t, or T lookup commands in the opposite direction
; Repeat the previous F, F, t, or T lookup commands
"NP Retrieval last nth Delete (the buffer contains a certain number of deletions, typically 9)
n repeat the preceding/or? Find command
N repeats the preceding/or in the opposite direction? Command
Save text and exit VI:
Command save and/or exit operations
: w save file but do not exit VI
: W file saves the modification in file but does not exit VI
: Wq or ZZ or save file and Exit VI
: q! Do not save file, Exit VI
: e! Discard all changes and edit from the last time the file was saved
options in VI:
Option action
: Set all to print all options
: Set nooption turn option option off
: Set Nu Prints line number before each line
: Set Showmode Whether the display is an input mode or a replacement mode
: Set autoindent The indentation of the previous line, especially for multi-line annotations
: Set Smartindent provides automatic indentation for C programs
: Set list display tabs (^i) and end-of-line symbols
: Set ts=8 sets tab for text input stops
: Set Window=n sets the text window to display n rows
: Set number shows rows
: Set Nonumber Suppress row count
Status of VI:
Option action
:. = Prints the line number of the current line
: = number of lines in the print file
CTRL+G Displays the file name, the current line number, the total number of rows in the file, and the percentage of the file location
: l Use the letter "L" to display many special characters, such as tabs and line breaks
to position paragraphs and place tags in text:
Option action
{insert {in the first column to define a paragraph
[[Back to the beginning of the paragraph]
]] to move forward to the beginning of the next paragraph
M (A-Z) marks the current position with a letter, such as the Mark Z with MZ
' (A-Z) moves the cursor to the specified marker, as with ' Z ' to move to Z
connect the lines in VI:
Option action
J connect the next line to the end of the current line
NJ Connection back N rows
cursor placement with screen adjustment:
Option action
H move the cursor to the top row of the screen
NH moves the cursor to line n on the top row of the screen
M moves the cursor to the middle of the screen
L move the cursor to the bottom row of the screen
NL moves the cursor to the nth line on the bottom line of the screen
^e (Ctrl+e) Scrolls the screen up one line
Ctrl+y rolling the screen down one line
Ctrl+u Roll the screen up half a page
Ctrl+d Roll the screen down half a page
CTRL+B Roll the screen up one page
CTRL+F Roll the screen down one page
Ctrl+l Redraw the screen
Z-return the current row to the top row of the screen
Nz-return Place the nth row below the current row as the top row of the screen
Z. Place the current row as the center of the screen
nz. Place the nth row on the current line as the center of the screen
Z to place the current row as the bottom row of the screen
nz-to place the nth row on the current line as the bottom row of the screen
Shell Escape command in VI:
Option action
:!command executes command commands for the shell, such as:!ls
:!! Execute the previous shell command
: R!command reads the input and insertion of command commands, such as: R!ls executes LS first and then reads the contents
: W!command the currently edited file as the standard input for the command command, and executes command commands, such as: W!grep all
: CD directory changes the current working directory to the directory represented by directory
: SH will start a child shell and use ^d (ctrl+d) to return VI
: So file reads and executes commands in Shell program file
macros and abbreviations in VI:
(Avoid using control keys and symbols, do not use characters K, V, G, Q, V, *, =, and function keys)
Option action
: Map key COMMAND_SEQ defines a key to run command_seq, such as: Map e ea, whenever you can move E to the end of a word to append text
: Map shows all defined macros in the status line
: Umap key Delete macro for this key
: AB string1 string2 defines an abbreviation that replaces string1 with string2 when inserting string1. When you want to insert text, type string1 and then press ESC, and the system inserts the string2
: AB shows all abbreviations
: Una string to cancel the abbreviation of string
indent text in VI:
Option action
Ctrl+i or tab when inserting text, insert moving width, moving width is defined beforehand
: Set AI turns on auto indent
: Set Sw=n Sets the move width to n characters
N> causes n rows to move one width to the right, such as 3>> to move the next three rows to the right by one moving width.
For more information:
1. Linux Vi/vim Text Editor ultra-detailed usage guide
2. Linux/ubuntu: Install the Vim text editor at the command line
3. Linux Vi/vim man Help documentation
Vim command Daquan/VI command Daquan