Read the Linux System VI (VIM) editor command using the tutorial __linux

Source: Internet
Author: User
Tags save file

VI (VIM) is a very common code Editor on Linux, many Linux distributions are installed by default VI (VIM). VI (VIM) command a wide range but if used flexibly will greatly improve the efficiency. VI is "visual interface" abbreviation, VIM is VI improved (enhanced version of VI). In general system Management Maintenance VI is enough, if you want to use the code highlighted can use VIM


Basically VI can be divided into three states, which are command mode, insert mode (insert modes), and bottom line mode (at last), the functions of each pattern are distinguished as follows:


1 Command mode

Controls the movement of the screen cursor, the deletion of characters, words, or rows, the movement of a section and the insertion mode, the bottom row mode.

2 Insert Mode

Only in insert mode, you can do text input, press the ESC key to return to command mode.

3 End Line Mode

To save or exit VI, you can also set up an editing environment, such as finding a string, listing line numbers. But generally we use the VI to simplify to two modes, that is, the bottom line mode is also included in the command mode. First, open the file, save, close the file (vi command mode to use)

VI filename//open filename File

: w//Save File

: w yusi123.com//Save to Yusi123.com file

: Q//Exit editor, if the file has been modified please use the following command

: q! Exit the editor without saving

: Wq//Exit editor, and save file Two, insert text or line (vi command mode to use, after executing the following command will enter insert mode, press Esc key to exit insert 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 (beginning of a non-empty character)
O//Create a new row above the current line
O//Create a new line below the current line
R//replace (overwrite) the current cursor position and several subsequent text
J//Merge cursor row and next behavior row (still in command mode) third, move cursor (vi command mode)

VI can be directly on the keyboard to move around the cursor up and down, but the normal VI is a lowercase English letter h, J, K, L, respectively, control the cursor left, down, up and right one lattice.


Press CTRL+B: The screen moves one page backward.

Press CTRL+F: The screen moves one page forward.

Press Ctrl+u: The screen moves half a page back.

Press Ctrl+d: The screen moves half a page forward.

Press number 0: Move to the beginning of the current line.

Press G: Move to the end of the article.

Press $: Moves to the end of the line where the cursor is located.

Press ^: Moves to the beginning of the line where the cursor is located.

Press W: The cursor jumps to the beginning of the next word.

Press e: The cursor jumps to the end of the next word.

Press B: The cursor returns to the beginning of the last word.

Press #l: Position where the cursor moves backward, such as: 5l,56l. Iv. Delete, restore character or line (used in VI command mode)

X: Every time you click, delete the following character at the position of the cursor.

#x: Deletes the following # characters at the position of the cursor, for example, 6x indicates the 6 characters after the location where the cursor is deleted.

X: Every time you click, delete the previous character in the position of the cursor.

#X: Deletes the front # character at the position of the cursor, for example, 20X represents the first 20 characters in the position where the cursor is deleted.

DD: Deletes the line where the cursor is located.

#dd: Deletes the # line starting at the line where the cursor is located. V, search (vi command mode to use)

/yusi123//To search the yusi123 string under the cursor
? yusi123//Search yusi123 string on the cursor
N//Down search before a check action
N//Search the previous search action Six, jump to the specified line (vi command mode to use)

n+//down Jump N line
N///Up Jump
NG//jumps to row number n
G//Jump to the bottom of the file seven, set line number (vi command mode to use)

: Set nu//Display line number
: Set Nonu//Cancel display line number Eight, copy, paste (vi command mode to use)

YY//Copy the current line to the buffer, or you can use "Ayy copy," A is a buffer, a can also be replaced by A to Z of any letter, you can complete multiple replication tasks.

Nyy//Copy the current line down n rows to a buffer, or you can use "Anyy copy," A is a buffer, a can also be replaced by A to Z of any letter, you can complete multiple replication tasks.


YW//Copy the characters from the beginning of the cursor to the ending.
NYW//Copy n words starting from the cursor.
y^//Copy the content from the cursor to the beginning of the line.
y$//Copy the content 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 for pasting.

P//Paste the contents of the Clipboard before the cursor, if the previous custom buffer is used, it is recommended to use the AP for pasting. ix. Replacement (use in VI command mode)

: s/old/new//Replace the first occurrence of old in the line with new
: s/old/new/g//Replace all old in line with new
: n,m s/old/new/g//Replace all old with new from N to M line
:%s/old/new/g//Replace all old 10 in the current file with new , edit other files

: E otherfilename//Edit file with file name Otherfilename. 11. Modify file Format

: Set Fileformat=unix//modify the file to UNIX format, such as the text file under win under Linux will appear ^m.

Note: If you do not know what mode you can press the ESC key 2 times to return to the command mode, there will be a final reminder: Note that case ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.