using the method described in detail vi
vi editor is a standard editor for Unix and Linux systems all, it is not inferior to any of the powerful new text editor, here is a brief introduction about its use and a small part of the instruction. Since any version of Unix and Linux systems, the vi editor is exactly the same, so you can learn more about it in any other place of introduction vi. Vi is the most basic Linux text editor, after learning it, you will be unimpeded in the Linux world.
1, the basic concept of vi
substantially vi can be divided into three states, namely, command mode (command mode), insert mode (Insert mode) and line mode (last line mode), to distinguish between functions of each mode is as follows:
1) command line mode command mode)
move the screen cursor control, to delete a character, word, or row, and move into the lower section of a copying Insert mode, or to the last line mode.
2) insert mode (Insert mode)
only in Insert mode, it can be done entering text, press the "ESC" key to return to the command line mode.
3) line mode (last line mode)
to save the file or exit vi, you can also set the editing environment, such as finding strings, lists the line number and so on .......
But generally we use the simplified two modes vi, is the bottom line mode (last line mode) can be considered the command line mode command mode).
2, vi basic operation
a) enter vi
after the system prompt type vi and the file name, then enter the vi full-screen editing screen:
$ vi myfile
But one thing is important to note that after you have entered vi, it is in the "Command Line mode (command mode), "you want to switch to" insert mode (insert mode) "to be able to enter text. Vi initial use of people will want to use the cursor keys to move around, the result has been the computer beep call, put their gas half to death, so after entering vi, the first not to tamper with, converted to "insert mode (Insert mode)" then we'll talk !
b) switch to insert mode (Insert mode) to edit the file
in the "command line mode (command mode)" click on the letter "i" can enter "insert mode (Insert mode)", this time you can start typing the .
c) Insert the switch
You are now in "insert mode (Insert mode)", you'll only have to enter text, if you find the wrong word! Want to move back with the cursor keys, delete the word, you must first click the "ESC" key to go to "command-line mode (command mode)" and then delete the text.
d) exit vi and save the file
under "command line mode (command mode)," click ":" colon to enter the "Last line mode", for example:
: w filename (enter "w filename" the article to the specified file save name filename)
: wq (enter "wq", save and exit vi)
:! q (input q !, force quit without saving vi)
3, command line mode (command mode) function keys
. 1) insert mode
press the "i "switch into insert mode" insert mode ", press" i "into the insert mode is the beginning of the input file from the current cursor position;
press" a "to enter the insert mode, is from a position of the current cursor position start typing;
press "o" into insert mode, inserting a new line, enter the text from the beginning of the line.
2). Insert mode is switched from the command line mode
press "ESC" key.
3) Move the cursor
vi can be directly with the cursor on the keyboard to move around, but the formal vi is the "h" in lower case letters, "j", "k", "l", respectively, to control the cursor left, down, on the right a grid.
Press "ctrl" + "b": "After" screen to the mobile page.
Press "ctrl" + "f": the screen to move "forward" page.
Press "ctrl" + "u": screen to move "backward" half a page.
Press "ctrl" + "d": the screen to move "forward" half page.
Press the number "0": move to the beginning of the article.
Press the "G": Move to the end of the article.
Press the "$": Move to the "end of line" cursor line.
Press the "^": "first line" to move the cursor line
by "w": the cursor jumps to the beginning of the next word
by "e": the cursor jumps to the next word suffix
by "b": the cursor returns at the beginning of the word
by "#l": # cursor to the first position of the line, such as: 5l, 56l.
4) delete the word
"x": every time you press Delete "behind" a character at the cursor position.
"#X": for example, "6x" means to delete the cursor position "behind" the six characters.
"X": uppercase X, every time you press Delete "in front of" a character at the cursor position.
"#X": for example, "20X" indicates the position of the cursor to delete the "front" of 20 characters.
"Dd": Delete cursor line.
"#Dd": # delete rows from the beginning of the line where the cursor
5) copy.
"Yw": the suffix characters to copy into the buffer at the cursor.
"#Yw": # copy words to the buffer
"yy": Copy the line where the cursor into the buffer.
"#Yy": for example, "6yy" said the bank copy from the cursor "down the number" 6 lines of text.
"P": the characters in the buffer attached to the cursor position. Note: All the "y" copy command must be related to the "p" to complete with copy and paste functions.
6).
"R": Replace character cursor wherever he went, and until you press the "ESC" key so far.
7) return the last operation
"u": If you mistakenly execute a command, you can immediately press the "u", return to the previous operation. Press repeatedly "u" can perform multiple responses.
8) Change the
"cw": Change the word at the cursor to the suffix of the
"c # w": for example, "c3w" means to change the three words
9) to jump to the specified line.
"Ctrl" + "g" row the line number where the cursor line.
"#G": for example, "15G" indicates to move the cursor to the article 15 of the first trekking.
4, Last line mode command Introduction
Before using the "last line mode", please remember to press the "ESC" key to confirm you are already in the next "command mode", press ":" colon can enter the "last line mode . "
A) lists the line number
"set nu": Enter "set nu", will be in front of each line in the file lists the line number.
B) jump to a line in the file
"#": "#" sign indicates a number, enter a number after the colon, press the Enter key will jump to the line, such as digital input 15, then Enter, it will jump to the article line 15.
C) Find the character
"/ Keyword": press "/" key, then enter the characters you want to find, if not the first to find the keywords you want, you can always press the "n" will be looking to future Until the keywords you want.
"? Keywords": "?" Press the button, and then enter the characters you want to find, if not the first to find the keywords you want, you can always press the "n" will be looking forward to the key you want Until word.
D) Save the file
"w": enter the letter "w" in the colon can be saved file.
E) vi leave
"q": Press the "q" is to quit, if you can not leave vi, may be in a "q" followed forced to leave vi "!."
"Qw": generally recommended to leave, with the "w" used together, so that when the exit can also save the file.
5, vi command list
1, the following are some of the keys in the command mode function
h represents a left cursor character
l denotes the right the cursor one character
k represents the cursor line
j represents a cursor by one line
^ represents the cursor to the beginning of the line
0 the number "0" , move the cursor to the beginning of the article
G represents a cursor to the end of the article
$ represents the cursor to the end of the line
Ctrl + f scroll forward
Ctrl + b scroll backward
Ctrl + d flip ahead half screen
Ctrl + u turned back half screen
i character is inserted before the cursor position
a cursor at a position after the character begins to increase
o insert a new row, beginning from the first line input
ESC retreat state from the command input state
x delete characters after the cursor
#x cursor deleted # of characters
X (uppercase X) delete character before the cursor
#X # delete characters before the cursor
dd delete cursor line
#dd # row number is deleted from the cursor line
a word copy cursor position YW
#yw copy the cursor position # word
yy copy location of the cursor line
#yy copied from the # line number of the cursor line
p paste
u cancel
cw to change the position of the cursor one word
#cw change # word at the cursor position
2, the following are some of the instructions in the command mode
w filename stored in the file being edited for the filename
WQ filename stored in the file being edited for the filename, and exit vi
q! Give up all changes and exit vi
the SET NU display line numbers
/ or? Search, in / enter're looking for
n use the / or? together, looking for keywords if the content is not want to find, press n or backward (with / MS) or forward (with? MS) to continue to find until you find it.
vi User's Manual
|
These are some basic vi command usage for subsequent read.