Use of Ubuntu under VI

Source: Internet
Author: User
Tags first string save file

Use of Ubuntu under VI

After SSH for the server file, I used to use gedit, but not good change, so use VI.

1, vi Basic concept of basically VI can be divided into three states, respectively, command mode, the insertion mode (insert modes) and the bottom line mode,
The functional distinctions of each pattern are 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, talent enough to do the text input, press "esc" to return to the command line mode.
3) Bottom Line mode
Save or Exit VI, you can also set the editing environment, such as looking for strings, 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 sign 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: Opens the file and places the cursor at the beginning of nth
vi + filename: opens the file and places 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: The last time you were editing with VI, a system crash occurred, 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" will be able to enter "Insert Mode", then you can start to enter the text.


c) Insert switch under "Insert Mode", you can only enter text, the word will be deleted, 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 the "last line mode", for example:
: w filename (enter "w filename" to save the article with the specified file name filename)
: 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 cursor from the current position to enter the file;
When you press "a" to enter insert mode, you start typing from the next position in the cursor position.
When you press "o" to enter insert mode, you insert a new line and enter text from the beginning of the start.


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 the lowercase English letter "h", "j", "k", "l", respectively, control the cursor left, bottom, upper, and right shift 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. [ultra-frequent use]
"#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 combined 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": Suppose you run a command by mistake, you can immediately press "u" and go back to the previous action. Press multiple times "U" to run multiple replies.


. :. Ability to run the last instruction 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. [ultra-frequent use]
#x: For example, the 6x table removes the trailing 6 characters from the cursor position. [Frequently used]
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 removes the first 20 characters from the position of the cursor.


DD: Deletes the line where the cursor is located.

[ultra-frequent use]
#dd: For example, the 6DD table deletes 6 lines of text from the line where the cursor is located. [Frequently used]

10). Instead of 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 passage from beginning to the beginning, and g means all substitution.
%S/STRING/REPLACE/C: The same will replace the full-text string strings with the replace string, and the above instruction is different,%s and 1, $s is the same function, C is to indicate to replace before you have to confirm the substitution. 1,20s/string/replace/g: Replaces a string between 1 and 20 rows with the Relpace string.


4, last line mode command simple introduction before using "last line mode", please remember to press the "esc" key to determine that you are already in the "command mode", and then press ":" Colon can 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, and then enter the character you want to look for, assuming the first time to find the keyword is not what you want, can always press "n" will look back to your keyword
So far.
「?

keyword": Press"?"first Key, and then enter the character you want to look for, assuming that the first time you find the keyword is not what you want, 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 exit, assuming you cannot leave VI, can be "q" followed by a "!" Forced to leave VI.

"qw": It is generally recommended to use with "w" when leaving, so that you can save the file when exiting.

 


Author:wsh

Email:[email protected]

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.