VI (VIM) is a very common editor on Linux, and many Linux distributions have VI (VIM) installed by default. VI (VIM) commands are numerous but if used flexibly it will greatly improve efficiency. VI is the abbreviation for "Visual Interface", Vim is VI improved (enhanced version VI). In general system Management Maintenance VI is sufficient, if you want to use code highlighting, you can use VIM. Below the VPS detective to organize the use of VI Tutorial: Contains VI basic introduction, usage mode, file open close save, insert text or new line, move cursor, delete, restore characters or lines, search, etc., is a more suitable for beginners to learn VI tutorial.
VI has 3 modes: insert mode, command mode, low line mode.
Insert mode: You can enter characters in this mode and press ESC to return to command mode.
Command mode: You can move the cursor, delete characters, and so on.
Low-line mode: can save files, exit VI, set VI, Find and other functions (low-line mode can also be seen as a command mode).
One, open file, save, close file (used in VI command mode)
VI filename//open filename File
: w//Save File
: w vpser.net//Save to Vpser.net file
: Q//Exit editor, if the file has been modified please use the following command
: q! Exits the editor without saving
: Wq//Exit editor, and save file
Second, insert text or lines (vi command mode to use, after executing the following command will enter the insertion mode, press ESC to exit the insertion mode)
A//Add text to the right of the current cursor position
I//Add text to the left of the current cursor position
A//Add text at the end of the current line
I//Add text at the beginning of the current line (the beginning of a non-empty character)
O//Create a new row above the current line
O//Create a new row below the current line
R//replace (overwrite) the current cursor position and several subsequent text
J//Merge cursor row and next line of behavior (still in command mode)
Third, move the cursor (used in the VI command mode)
1, use the upper and lower left and RIGHT arrow keys
2, Command mode: H left, J down, k up, l to the right.
Spacebar to the right, Backspace left, Enter to the next line,-move to the top of the line.
Iv. Delete, restore characters or lines (used in VI command mode)
X//Delete current character
NX//delete n characters starting from the cursor
DD//Delete when moving forward
NDD//Down Delete the current row, including n rows
U//Undo Previous action
U//Undo all operations on the current line
V. Search (used in the VI command mode)
/vpser//Search for Vpser strings under cursor
? vpser//Searching for vpser strings on the cursor
N//down searches for previous search action
N//Up search previous search action
Six, jump to the specified line (vi command mode use)
n+//Jump down N rows
N//Jump up N rows
NG//jumps to rows with line number n
G//Jump to the bottom of the file
Seven, set the line number (vi Command mode use)
: Set nu//Display line number
: Set Nonu//Suppress line numbers
Eight, copy, paste (used in the VI command mode)
YY//Copy the current line to the buffer, you can also use "Ayy copy," A is a buffer, a can also be replaced by any letter A to Z, you can complete multiple replication tasks.
Nyy//Copy the current row down n rows to the buffer, or you can use "Anyy copy," A is a buffer, a can also be replaced with any letter A through Z, you can complete multiple replication tasks.
YW//Copy the character from the beginning of the cursor to the ending.
NYW//Copy n words starting from the cursor.
y^//Copy the contents from the cursor to the beginning of the line. VPS Detective
y$//Copy the contents from the cursor to the end of the line.
P//Paste the contents of the Clipboard after the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."
P//Paste the contents of the Clipboard before the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."
Ix. replacement (used in the VI command mode)
: S/old/new//Replaces the first occurrence of old in a row with new
: s/old/new/g//Replace all old in line with new
: n,m s/old/new/g//Replace all old from N to M with new
:%s/old/new/g//Replace all old in current file with new
X. Editing other documents
: E otherfilename//edit file named Otherfilename.
Xi. Modifying file formats
: Set Fileformat=unix//modify the file to UNIX format, such as win below the text file under Linux will appear ^m.
Summary: VI (VIM) tutorial Although there are more commands, but as long as the practice, I believe you will quickly mastered, but also to your work or study to bring more efficiency. When you don't know what mode you are in, you can press the ESC key 2 times to return to the command mode, there will be a final reminder: Pay attention to the case!!!
If you have any questions, please leave a message or talk to the VPS forum.
Original articles, reprinted with the consent of the author, and must be in the form of a link to indicate the source.
>> Reprint Please specify the Source: VPS Detective This article link address: http://www.vpser.net/manage/vi.html
Using the VI (VIM) editor on Linux tutorial