When using a text editor to process a file, the editor copies the file into the memory, which is called buffer. Retain the original file in the deposit, and modify the files in the buffer. If the editing is complete, if you want to save, use the Write command to copy the files in the buffer to the deposit, replace the original file and release the buffer. If you don't want to save the modified file, just use the quit command to exit the editor.
Enter VI in the system prompt to enter the editing environment. VI has two operating modes:
(1) Text input mode: input text operation
(2) Edit Command Mode: Under the file editing, storage, and exit VI, etc. Operation commands. When running VI, you will first enter the command mode, and any characters entered at this time are considered commands.
1.2 Basic use of the VI editor
1.2.1 VI usage example:
After registering the system, enter the system prompt:
Vi filename // filename To bring an extension, otherwise the default is a text file
Such as: Vi Test.c
Press INSERT to enter text editing. For example, enter the following code:
#include
Main ()
{
Printf ("this is my first c program under linux!");
}
After entering, press "ESC" and ":" to return to the command mode.
The following describes the use of the REDO command:
For example, after pressing the ESC button to end the Insert mode, press "." Button at this time, display:
#include
Main ()
{
Printf ("this is my first c program under linux!");
}
#include
Main ()
{
Printf ("this is my first c program under linux!");
}
That is, INSERT command is re-executed. It should be noted that the location of the paste depends on the position of the cursor.
The unmistone command is: u.
1.2.2 Text Enter Command:
(1) Additional (APPEND):
a Add the new text to the position where the cursor is located.
A Put the new text to the end of the row in the cursor.
(2) Insert (INSERT):
i Insert the text to the front of the position of the cursor, and the text after the cursor is newly moved backward.
I begins with the first non-empty character in front of the cursor in front of the cursor.
(3) Start (Open):
o make the new text independently and insert the next line of the cursor
1.2.3 Delete and modification
Move the basic command of the cursor:
After entering the command mode:
H cursor left shift a character J cursor down one line (QUIT) K cursor moves a row L cursor right shift a character
The commands that delete and modify have the following:
x Deleting the character DD where the cursor is located, the row R where the cursor is located, and then enter the character R to correct the character R to enter the replacement state. The newly entered text will overwrite the original text until [ESC] button back To the command mode, the character is deleted and enters the input mode S to delete the row where the cursor is located and enter the input mode YY Copy the entire line of text CC to modify the entire line of text D De Delete the cursor to the end of the line.
1.2.4 file command
The file command starts with ":". Common file commands are shown in the table below: