The basic method of use of the VI editor!

xiaoxiao2021-03-06  95

The VI editor is the standard editor under all UNIX and Linux systems, and its powerful is not in any latest text editor, just simply introduces its usage and a small part of the instruction. Due to any versions of UNIX and Linux systems, the VI editor is exactly the same, so you can learn more about it in any other place to introduce VI. VI is also the most basic text editor in Linux. After learning it, you will walk in Linux world.

1, the basic concept of VI basically VI can be divided into three states, which are command mode, insert mode, and bottom line mode, the functionality of each mode is as follows:

1) Command line mode Command Mode)

Control the movement of the screen cursor, the deletion of characters, words or rows, moving copy a certain section and entering insert mode, or to Last Line Mode.

2) Insert mode (INSERT MODE)

Only if you are in Insert Mode, you can do text input, press the "ESC" button to return to the command line mode.

3) Last Line Mode

Save or exit the file or exit the VI, you can also set the editing environment, such as looking for strings, listing line numbers ... etc.

However, we will simplify the VI into two modes when using it, which is also the Last Line Mode, which is also in the command line mode Command mode.

2, the basic operation of VI A) Enter vi

After entering the VI and file name of the system prompt symbol, enter the VI full screen editing screen:

$ vi myfile

However, it is necessary to pay special attention to the "Command Mode" after you enter the VI, and you have to switch to the "Insert Mode" to enter text. In the first time, people who use VI will want to move the cursor with the upper and lower left, and the computer has been supple, and she is too dead. So after entering VI, do not move, switch to "Insert Mode" again. " !

b) Switch to Insert Mode Edit file

When you click on the "Command Mode", you can enter "Insert Mode", you can start entering the text.

c) Insert switching

You are currently in "Insert Mode", you can only enter text, if you find the wrong word! Want to move back with the cursor button, delete the word, just press the "ESC" button to transfer the text again.

d) Exit VI and save files

Under "Command Mode", press ":" colon key to enter "Last Line Mode", for example:

: w FileName (Enter "W FileName" Save the article with the specified file name filename)

: WQ (enter "WQ", save and exit VI)

: q! (Enter Q!

3, command line mode (Command Mode) function key 1). Insert mode

Press "I" to switch into the insert mode "INSERT MODE", press "I" to enter the insert mode is started from the cursor's current position; press "A" to enter the insert mode, it starts from the next position where the current cursor is located. Enter text;

After entering the insert mode according to "O", it is inserted into a new line, and the text will be entered from the head.

2) Switch from the insert mode to command line mode

Press the "ESC" button.

3). Move cursor

VI can be directly moved with the cursor on the keyboard, but the regular VI is using lowercase English letters "H", "J", "K", "L", controls the left, bottom, upper and right movement of the cursor, respectively. grid.

Press "Ctrl" "B": The screen moves "post" moving a page.

Press "Ctrl" "F": The screen moves to "before".

Press "Ctrl" "U": The screen is moving halfpage.

Press "Ctrl" "D": The screen moves "before".

Press Number "0": Move to the beginning of the article.

Press "G": Move to the end of the article.

Press "$": Move to the "row" of the line where the cursor is located.

Press "^": "Live" to move to the direction of the cursor

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

Press "E": The cursor jumps to the word of the next word.

Press "B": The cursor returns to the beginning of the previous word

Press "#L": The cursor is moved to the top position of the line, such as: 5L, 56L.

4). Delete text

"X": Every time, delete the "back" character in the location of the cursor.

"#X": For example, "6x" means "back" 6 characters that delete the location of the cursor.

"X": uppercase X, once a one, delete the "front" character in the location of the cursor.

"#X": For example, "20X" means the "front" 20 characters that delete the location of the cursor.

"DD": Deletes the cursor.

"#Dd": Delete # lines from the row of the cursor

5). Copy

"YW": Copy the character where the cursor is located to the snipper to the buffer.

"#Yw": copy # 个 到 to the buffer

"YY": Copy the cursor to the buffer.

"#Yy": For example, "6yy" means that the copy from the row "of the cursor" to the lower number "6 line text.

"P": attach characters in the buffer to the location of the cursor. Note: All replication commands related to "Y" must match "P" to complete replication and paste function.

6). Replace

"R": Replace the characters where the cursor is located.

"R": Replace the characters from the cursor until the "ESC" button is pressed.

7). Reply to the last operation

"U": If you write a command, you can press "U" immediately and return to the previous operation. Multiple reply can be performed by "U" multiple times.

8). Change

"CW": Change the word to the word where the cursor is located

"C # W": For example, "C3W" means changes 3 words

9). Jump to the specified line

"Ctrl" "G" lists the line numbers in the row where the cursor is located.

"#G": For example, "15G", represents the first line of moving cursors to the article.

4, Last Line Mode Under Under Use before using "Last Line Mode", please remember to press the "ESC" button first. After you are already in "command mode", press ":" to enter "Last Line Mode" .

A) list the line number

"Set Nu": After entering "Set Nu", the line number will be listed in each of the files.

B) Jump to a line in the file

"#": "#」 "Represents a number, enter a number after the colon, then press the Enter key, you will jump to the line, such as entering the number 15, then enter, you will jump to the 15th line of the article. . C) Find characters

"/ Keyword": press the "/" button first, enter the character you want to find, if the keyword for the first time is not what you want, you can press "N" to find the key to you. Word.

"? Keyword": press "?" Button first, enter the character you want to find, if the first time I find the keyword is not what you want, you can always press "N" to find the key to you. Word.

D) save the file

"W": You can save the files in the colon.

E) Leaving VI

"Q": Press "Q" to quit, if you can't leave Vi, you can force the VI after "Q".

"QW": When it is recommended to leave, use "W" to use "W", so you can save files when you exit.

5, VI Command List 1, the following table lists the functions of some keys in command mode:

h left left shimming a character

l right shot a character

K cursor is moved on a row

J cursor moved down

^ Cursor moves to the head

0 Digital "0", the cursor moves to the beginning of the article

G cursor moved to the end of the article

$ Cursor to move to the end

Ctrl fwards forward

Ctrl b backwards

Ctrl D flushing half screen

Ctrl u backward screen

i insert characters in front of the cursor position

A The latter character starts to increase after the cursor is located

o Insert a new line, starting from the head of the lead

ESC returns from the input status to the command status

x Delete characters behind the cursor

#x Delete # characters after the cursor

X (uppercase x), delete characters in front of the cursor

#X Delete # characters in front of the cursor

DD Deletes the line where the cursor is located

#dd delete # lines from the number of rows from the cursor

YW Copy a word in the location of the cursor

#YW Copy the position of the cursor location # 个

YY Copy the position of the cursor location

#yy copy from the number of rows where the cursor is located

p stick

u cancel operation

CW Changes a word in the location of the cursor

#CW Change # 个 个 in the location of the cursor

2, the following table lists some instructions in the line command mode W FileName Store the file being edited to filename

WQ filename stores the file being edited as FileName, and exits VI

q! Abandon all modifications, exit VI

Set nu display line number

/ Or? Find, enter the content you want to find after / after

N with / or? If the content of the lookup is not the keyword you want to find, press N or back (with / in use) or forward (contact with?) until it is found.

For the first time with VI, there are a few alert to remind: 1. Open the file with the VI, is "command mode", you want to switch to "Insert Mode" to enter text . Switching method: You can enter "Insert Mode" in "Command Mode" and click "Insert Mode", you can start entering text. 2. After editing, you need to switch from the insert mode to command line mode to save the file, switch the method: Press the "ESC" button. 3, save and exit file: Enter: WQ in command mode! (Don't forget the front of WQ :)

转载请注明原文地址:https://www.9cbs.com/read-105001.html

New Post(0)