Use of Ubuntu under VI

Source: Internet
Author: User
Tags first string save file

Use of Ubuntu under VI

SSH after the server files, I used to use gedit, but not good modification, so use VI.

1, vi basic concept basically VI can be divided into three kinds of states, namely command mode, insert mode (and bottom line mode),
The functions of each mode are differentiated 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, when we use the VI to simplify the two mode, that is, the bottom row mode (last lines) is also counted in the command line mode.
2, VI Basic operation a) Enter VI in the system hint symbol VI and file name, enter the vi full Screen editing screen:
$ VI myfile
Note that after you enter VI, you are in command mode, and you want to switch to insert mode to enter text. So, don't move, switch to insert mode.
VI FileName:Opens or creates a new file and places the cursor at the beginning of the first
vi +n FileName:Open the file and place the cursor at the beginning of nth
vi + filename:Open the file and place the cursor at the beginning of the last line
vi +/pattern filename: Opens the file and places the cursor at the first string that matches the pattern
vi-r FileName:A system crash occurred last time you were editing with VI, restoring filename
VI filename....filename:Open multiple files, edit them sequentially
b) switch to insert mode to edit the file in "command mode" click the letter "i" can enter "Insert Mode", then you can start to enter the text.
c) Insert switch under "Insert Mode", you can only enter text, when you delete the word, you must first click the "esc" key to go to the command line mode
mode) and delete the text (or delete).
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)
W FileName: Save the file being edited as filename
WQ FileName: Save the file being edited as filename and exit VI
q!: Discard all changes, exit VI
3, command-line 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 by pressing the "esc" key.
3). Move the cursor vi can be directly with the cursor on the keyboard to move up and down, but the normal VI is a 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: (Note is the number 0) the cursor moves to the beginning of the current line.
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" or W: cursor jumps to the beginning of the next word
Press "e" or E: cursor jumps to the end of the next word
Press "b" or B: The cursor returns to the beginning of the last word
Press #l: The cursor moves to the first # position of the line, such as: 5l,56l.
Space: Move the cursor right one character
Backspace: Cursor moves left one character
K or ctrl+p: Move the cursor up one line
J or CTRL + N: Move the cursor down one line
Enter: Move the cursor down one line
): Move the cursor to the end of the sentence
(: The cursor moves to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Cursor moves to end of paragraph
NG: Cursor moves to the beginning of nth
n+: The cursor moves down n rows
N: Move the cursor up n rows
n$: Cursor moves to end of Nth line
H: Move the cursor to the top row of the screen
M: Move the cursor to the middle line of the screen
L: The cursor moves to the last line of the screen
$: Cursor moves to the end of the current line
4). Copy "yw": Copies the character at the end of the cursor to the buffer.
"#yw": Copy # words to Buffer
"yy": The line where the cursor is copied. [Exceptional]
"#yy": for example, "6yy" represents a copy of 6 lines of text from the line where the cursor is located.
"p": Paste that pastes the characters in the buffer to the cursor position. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.
"Ayy: Put the copied row in buffer A, VI provides the buffer function, can be used to present the data buffer
"AP: Paste the data placed in buffer a.
"B3yy: Deposit three rows of data into buffer B.
"b3p: Paste the data that exists in buffer B
5). 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.
6). 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.
. :. The last instruction can be executed repeatedly.
7). Change "cw": Change the word at the end of the cursor
"c#w": For example, "c3w" represents a change of 3 words
8). Jumps 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.
9). Delete operation (press ESC to convert back to command mode, and then delete text) x: Deletes the next character at the location of the cursor every time you press it. [Exceptional]
#x: For example, the 6x table deletes the next 6 characters in the position of the cursor. Common
X: An x in large print, each time the first character in the position of the cursor is deleted.
#X: For example, the 20X table deletes the first 20 characters in the position of the cursor.
DD: Deletes the line where the cursor is located. [Exceptional]
#dd: For example, the 6DD table deletes text that is 6 lines down from the line where the cursor is located. Common
10). Replace string 1, $s/string/replae/g: enter "1, $s/string/replace/g" in last line mode to replace the full-text string with the Replace string, where 1,$ s means that the search interval is the meaning of the article from beginning to the beginning, and G means replacing it without confirmation.
%S/STRING/REPLACE/C: Similarly, the full-text string string is replaced with the replace string, and the above instruction is different,%s and 1, $s is the same function, and C is to indicate that the substitution must be confirmed again before being substituted. 1,20s/string/replace/g: Replaces a string between 1 and 20 rows with the Relpace string.
4. Last command in line mode before using "last line mode", remember to press "esc" to make sure you are already under "command mode", 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 "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as enter the number 15, and then enter, will jump to the 15th line of the article.
C) Find the character "/keyword": First press the "/" key, then enter the character you want to find, if the first keyword is not what you want, you can always press "n" will look back to the keyword you want
So far.
"? keyword": Press "?" first 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 forward to the keyword you want
So far.
D) Save file "w": Enter the letter "w" the colon to save the file.
E) Leave vi"q": Press "q" is quit, 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.


Author:wsh

Email:[email protected]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of Ubuntu under VI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.