Vi editor and vi editor commands
Reprinted please mark: http://www.cnblogs.com/winifred-tang94/
To start the vi Editor, enter the vi command directly at the command prompt. to edit a file, use the "vi file name" method. As shown in, the last row of the window is the status bar, including the file name, file size, and file read/write attributes:
There are three ways to operate the Vi Editor:
A. Command method. The vi editor was just started in command mode.
B. editing mode. If you want to enter the editing mode, you can enter a command in the command mode to enter the editing mode. For example, the command for attaching data and the I command for inserting data. Enter the esc key to return the command method from the editing method.
C. The ex escape method (the ex editor command is called in the vi editor to complete the editing operation). Enter the command in the command mode to enter the ex escape method. After entering the ex escape mode, you can enter the (ex command prompt) and then enter the ex command to go to the ex mode for editing.
Note:: When editing the squadron file in the vi editorEdit BufferTo modify the file, enter the w (ex command) command or other commands to write the file to the disk.
Function keys in the Vi Editor:
<Esc> key: Used to end the editing mode and re-enter the command mode.
<Enter> key: when the ex escape mode is used, enter makes the ex command take effect and exit the ex escape mode to return the command method.
/: Enter a string or character after/to search for the string or character from the current position. When the first string or character to be searched is found, click n to jump to the next matching value.
? :? And.
As shown in: enter esac after/and press enter to find the matching string.
Exit vi Editor:
Command ZZ: Run ZZ to save the current modification and exit the vi editor.
Ex command: x -- saves the current modification and releases vi;
Ex command: q -- exit
Ex command: q! -- Exit but not save.
Vi editor commands in command mode:
A. cursor movement command:
Move to the next line: enter and Arrow
Move to the beginning of the row: 0
Move to the end of the row: $
Move to a row: First press the row number and then press G, the cursor jumps to the first character of the specified row number.
Move to the beginning of the sentence :(
Move to end of sentence :)
Move to the beginning of the field :{
Move to the end of the paragraph :}
B. text editing commands
Insert at the current position. With the I command, the entered characters are inserted before the characters in the cursor.
Append it at the current position. With the command, the entered characters are inserted after the character of the current cursor.
Append the following command to the end of the current line:
Start a new row: o creates a new row under the current row, O creates a new row above the current row
C. Text deletion command
The X command deletes the character at the current cursor position, and the X command deletes the character before the current cursor position.
Dw deletes a word at the current position. d $ deletes the word from the current position to the end of the row. dd deletes the current row.
Note:: Put the deleted text in a set of buffer stacks, the buffer stack number ranges from 1 to 9, and the last deleted text in the buffer stack 1, you can run the p command to put the last deleted text in the next line of the current line. To retrieve other text, run the command: + buffer stack number + p.
D. Text modification command
During the editing process, the modification may be undone when a modification error occurs. The u command revokes the previous modification and the U command revokes all the modifications made since they entered the current row.
E. Text movement and copying
You can also copy and move files in the vi editor.
If you want to copy data, use the y and p commands. If you want to copy the current row, run the "yy" command, move the cursor to the position to be added, and run the "p" command to paste the copied row. You can add a number before yy to indicate the number of rows. For example, 3yy indicates that all three rows starting from the current position are copied.
If you want to move the data, you need to combine the d command and the p command. We have previously said that the dd command deletes the current line. After the dd command deletes the current line, move the cursor to the position where you want to move the cursor. Execute the p command to move the row that was deleted. -- The reason for this is that the deleted data is stored in the buffer zone of vi.
Escape commands in the Vi Editor
Write command --: w
READ command --: r file name (this command can be used to read external files from the opened file)