VI
Editoris the standard for all UNIX and Linux systems
EditorThat it's powerful not inferior to any of the latest text
Editor, here is simply a brief introduction to its usage and a small number of instructions. Because of any version of UNIX and Linux systems,
VIThe editor is exactly the same, so you can make any other introductory
VIPlace to learn more about it. VI is also the most basic text editor in Linux, after learning it, you will be in the world of Linux unimpeded.
1, VI of the basic concept
Basically, vi can be divided into three states, namely command mode, insert mode (and bottom line mode), and the function of each mode is as follows:
1) command-line mode
Controls the movement of the screen cursor, the deletion of characters, words, or lines, moving and copying a section and entering insert mode, or to last line mode.
2) Insert mode
Only in the Insert mode, you can do text input, press "esc" to return to the command line mode.
3) Bottom Line mode
Save or Exit VI, or you can set the editing environment, such as looking for a string, listing line numbers ... such as
In general, however, we simplify the VI into two modes when we use it, that is, the bottom row mode (last line mode) is also counted as the command-line pattern.
2, VI of the basic operation
A) Enter VI
After the system prompt symbol to enter VI and file name, go to the VI Full screen editing screen:
$ VI myfile
However, it is important to note that after you enter VI, you are in command mode and you want to switch to insert mode to enter text. First Use VI people will want to use the next key to move the cursor, the result of the computer has been a beep, the gas to death, so enter the VI, do not move, switch to "insert mode" and then!
b) switch to insert mode to edit the file
Press the letter "i" under Command mode to enter "Insert Mode", and you can start typing the text again at this point.
c) Toggle of Insert
You are currently in "Insert Mode", you can only enter text, if you find the wrong word! To move back with the cursor key, delete the word, then click the "esc" key to go to "command mode" and then delete the text.
d) Exit VI and save the file
Under Command mode, click the ":" colon key to enter "last line mode", for example:
: w filename (enter "w filename" to save the article with the filename you specified)
: Wq (input "wq", save and Exit VI)
: q! (Enter q!, do not save the mandatory exit VI)
3. Command mode function key
1). Insert mode
Press "i" switch into insert mode "insert mode", press "I" into the insertion mode is the beginning of the cursor from the current position to enter the file;
After pressing "a" into insert mode, the text is entered from the next position at the current cursor position;
When you press "o" to enter insert mode, you insert a new line and enter text from the beginning of the beginning.
2). Switch from insert mode to command line mode
Press the "esc" key.
3). Move the cursor
VI can be directly on the keyboard with the cursor to move up and down, but the normal VI is the lowercase English letter "h", "j", "k", "l", respectively, control the cursor left, bottom, upper, and right one grid.
Press "ctrl"+"b": The screen moves one page to the back.
Press "ctrl"+"f": The screen moves one page to the front.
Press "ctrl"+"u": The screen moves the half page toward the back.
Press "ctrl"+"d": The screen moves the half page toward the front.
"0" by number: Moves to the beginning of the article.
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": Cursor jumps to the beginning of the next word
Press "e": Cursor jumps to the end of the next word
Press "b": Cursor back to the beginning of the last word
Press #l: The cursor moves to the first # position of the line, such as: 5l,56l.
4). Delete text
"x": Each time you press the cursor, delete the "after" character at the position where the pointer is located.
#x: For example, "6x" represents the "after" 6 characters of the location where the cursor was deleted.
"x": Uppercase X, each time it is pressed, deletes the "front" character at the location of the cursor.
"#X": for example, "20x" represents the "front" 20 characters of the location where the cursor was deleted.
"dd": Delete the line where the cursor is located.
"#dd": Deletes the # line starting at the line where the cursor is located
5). Copy
"yw": Copies the characters from the cursor to the end of the word into the buffer.
"#yw": Copy # words to Buffer
"yy": Copy cursor line to buffer.
"#yy": for example, "6yy" represents a copy of 6 lines of text from the line where the cursor is located.
"p": Paste the characters in the buffer to the cursor location. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.
6). Replace
"r": Replaces the character at which the cursor is located.
"r": Replaces the character where the cursor is located until the "esc" key is pressed.
7). Reply to Last action
"u": If you mistakenly execute a command, you can press "u" immediately to go back to the previous action. Multiple replies can be performed by pressing "U" multiple times.
8). Change
"cw": Change the word-to-tail at the cursor location
"c#w": For example, "c3w" represents a change of 3 words
9). Jump to the specified line
"ctrl"+"g" lists the line number of the line where the cursor is located.
"#G": for example, "15g", which means moving the cursor to the beginning of the 15th line of the article.
4. Next line Mode command brief
Before using "last line mode", remember to press "esc" to make sure you are under "command mode" and then press ":" Colon to enter "last line mode".
A) List line numbers
"set nu": After you enter "set nu", the line numbers are listed before each line in the file.
B) jump to a line in the file
The "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as entering the number 15, and then enter, you will jump to the 15th line of the article.
C) Find characters
"/Keyword: First press the"/"key, and then enter the character you want to look for, if the first keyword is not what you want, you can always press"n"will look back to the keyword you want.
"? keyword": Press "?" first Key, and then enter the character you want to find, if the first keyword is not what you want, you can always press "n" will look forward to the keyword you want.
D) Save the file
"w": Enter the letter "w" the colon to save the file.
E) Leave VI
"q": Press "q" is to exit, if you cannot leave VI, can be "q" followed by a "!" Forced to leave VI.
"qw": Generally recommended to leave, use with "w", so you can also save the file when exiting.
5. VI Command List
1. The following table lists the functions of some keys in the command mode:
H
Move left cursor one character
L
Move the cursor one character to the right
K
Move the cursor up one line
J
Move the cursor down one line
^
Cursor moves to the beginning of the line
0
Number "0", the cursor moves to the beginning of the article
G
Cursor moves to the end of the article
$
Move cursor to end of line
Ctrl+f
Flip the screen forward
Ctrl+b
Flip the screen backwards
Ctrl+d
Turn Half-screen forward
Ctrl+u
Turn Back half screen
I
Insert a character before the cursor position
A
The next character at the cursor position begins to increment
O
Insert a new row, starting at the beginning of the line
Esc
Fallback from input state to command state
X
Delete the character following the cursor
#x
# characters after the cursor is deleted
X
(uppercase x), delete the character in front of the cursor
#X
Delete the # characters before the cursor
Dd
Delete the line where the cursor is located
#dd
Remove the # line from the number of lines that the cursor contains
yw
Copy a word where the cursor is located
#yw
Copy the # Word where the cursor is located
Yy
Copy a row where the cursor is located
#yy
Copy the # line from the number of lines where the cursor is located
P
Paste
U
Cancel operation
cw
Change a word in the position of your cursor
#cw
Change the # Word where the cursor is located
2, the following table lists some instructions in the line command mode
W filename
Save the file you are editing as filename
WQ filename
Save the file being edited as filename and exit VI
Q!
Discard all changes, exit VI
Set Nu
Show line Numbers
Or?
Find, enter what you are looking for in/after
N
with/or, if the search is not the keyword you are looking for, press N or backwards (with/to) or forward (with?) to continue looking until you find it.
For the first use VI, there are a few notes to remind:
1. When you open a file with VI, you are in command mode, and you want to switch to insert mode to enter text. Toggle method: Click on the letter "i" "Command mode" to enter "Insert Mode", then you can start to enter the text.
2, after editing, you need to switch from insert mode to command line mode in order to save the file, switch method: Press the "esc" key.
3. Save and exit the file: Enter in command mode: WQ! (Don't forget to wq the front)
VI User manual
VI is the most commonly used text editing tool on Unix, as a UNIX software tester, it is necessary to master it. Command VI to enter VI FileName: Opens or creates a new file and places the cursor at the beginning of the first VI+n FileName: Opens the file and places the cursor at the beginning of the nth Line VI+FileName: Opens the file and places the cursor at the beginning of the last line VI+/pattern FileName: Opens a file and places the cursor at the first string that matches the pattern VI-r filename: A system crash occurred during the last edit with VI, restore Filenamevi filename....filename: Open multiple files, edit the Move Cursor class command h: Move the cursor left one character l : The cursor moves right one character space: The cursor moves right one character backspace: The cursor moves left one character K or ctrl+p: Move the cursor up one line J or ctrl+N: The cursor moves down one line enter: The cursor moves down a line of W or W: The cursor moves to the right of a word to the first B or B: The cursor moves left one word to the beginning E or e: The cursor moves to the end of a word J to the end of the word: The cursor moves to the beginning of the sentence (: Cursor moves : Cursor moves to end of paragraph ng: Cursor moves to nth beginning n+: The cursor moves down n rows n-: The cursor moves up N line n$: The cursor moves to the nth line end H: The cursor moves to the top line of the screen m: the cursor moves to the middle line of the screen L: the cursor moves to the last line of the screen0: (note is the number 0) the cursor moves to the current line at the beginning of $: the cursor moves to the current row end of the screen tumbling Class command Ctrl+u: Flip the file to the top half screen Ctrl+d: Flip the file to the end of the half screen Ctrl+F: Flip a screen to the end of the file ctrl+b; Scroll to the top of the file. NZ: Rolls the nth line to the front of the screen without specifying N to roll the current line to the top of the screen. Insert Text Class command I: Before cursor I: At the beginning of the current line a: After the cursor A: At the end of the current row o: A new line below the current line O: New line above the current row R: replace the current character R: replace the current character and its subsequent characters until the ESC key s: Starts at the current cursor position. Replaces the specified number of characters with the entered text s: Deletes the specified number of lines and replaces the NCW or NCW with the text entered: modifies the specified number of words NCC: Modifies the specified number of rows to delete a command NDW or NDW: Delete the beginning of the cursor and its post n-1 Words Do: Delete to beginning d$: Cut to end of line NDD: Deletes the current row and its latter n-1 rows x or x: Deletes one character, x deletes the cursor, and x deletes the CTRL before the cursor+u: Delete the text search and replace command entered in the input mode:/Pattern: Searches for pattern at the end of a file from the beginning of the cursor?pattern: Search from the beginning of the cursor to the top of the file Patternn: Repeat the last search command in the same direction N: Repeat the previous search command in the opposite direction: s/p1/p2/g: Replace all P1 in the current line with P2: N1,n2s/p1/p2/g: Replace all P1 in line N1 to N2 with P2: g/p1/s//p2/g: Replace all P1 in the file with P2option Set All: Lists all option settings term: Set terminal type ignorance: Ignore case in search list: Display tab stop (Ctrl+I) and line tail sign ($) Number: Display line number report: Displays the amount modified by the line-oriented command terse: Displays a brief warning message warn: Displays No if the current file is not saved when you go to another file Write information nomagic: Allows the use of special characters that are not preceded by "\" In search mode Nowrapscan: Prohibit VI when the search reaches the end of the file, And start at the other end. MESG: Allow VI to display the last line of information that other users write to their terminal using Write command: N1,N2 CO N3: Copy the contents of the N1 line to the N2 row below the N3 line: n1,n2 m N3: Move the contents of the N1 line to the N2 line to the next N3 line: n1,n2 D: Delete the contents of the N1 row to the N2 row: w: Save the current file: E filename: Open file filename for editing: x: Save the current file and exit: Q: Exit Vi:q!: Do not save the file and Exit VI:!Command : Execute shell command command:n1,n2 w!command: The contents of the N1 line to the N2 line in the file as input and execution of the command, if not specified n1,n2, the entire file content as the command input: R!command: Places the output of command commands on the current line.
How to use the Linux Editor vi detailed introduction