First Knowledge VI Editor

Source: Internet
Author: User
Tags first string

VI Basic concepts are neither introduced, Baidu, Wiki has. Below is a brief summary of what I have learned from VI,

1.VI is divided into three states: Command mode, insert mode, and bottom line mode.

(1). command line pattern-command mode

is to control the movement of the screen cursor, mainly into the insertion mode and the bottom line mode of the neutral (like a manual file, the shift is the first to enter the gap in the other gear)

(2). Insert mode

A veritable insert mode in which you can only insert text into the action (highlighted here), and only in this mode can you enter text into the document

(3). Bottom row mode (last line mode)

What you see is what you get, which is the mode at the bottom of the line, typically saving or exiting the currently edited text.

-->TIP1: Enter VI editor with VI command, in command mode. After the most basic and general practice is: 1. [I] the letter enters the insertion mode; 2. [:] Enters the bottom row mode. 3. Pressing the [ESC] key in any mode will return to the command mode.

2. Detailed usage of the commands in the various modes is described in detail below

(I. Command-line mode:

1). Insert mode

Press "i" to switch into insert mode "insert mode", press "I" to enter the insertion mode is the beginning of the cursor from the current position of the input file, press "a" into the insertion mode, the current cursor from the location of the next position to start typing text;

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.

(II. End-of-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.

3. Finally attach the 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 line 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

Move Cursor Class command

H: Move the cursor one character to the left

L: Move the cursor right one character

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 a line w or w: Move the cursor right one word to the beginning of the word

B or B: The cursor moves left one word to the beginning of the word

E or E: Move the cursor right one word j to the end of the word

): 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

0: (note is the number 0) cursor moves to the beginning of the current line

$: Cursor moves to current line end screen Tumbling Class command

Ctrl+u: First half screen to file

Ctrl+d: Half-screen to the end of the file

CTRL+F: Flip a screen to the end of a file

ctrl+b; Turn one screen to the top of the file

NZ: Rolls line N to the top of the screen and scrolls the current line to the top of the screen when n is not specified.

Insert Text Class command

I: Before the cursor

I: At the beginning of the current

A: After the cursor

A: At the end of the current line

O: A new line below the current line

O: New row above the current line

R: Replace the current character

R: Replaces the current character and its characters until the ESC key is pressed

S: replaces the specified number of characters with the input text starting at the current cursor position

S: Deletes the specified number of rows and replaces them with the input text

NCW or NCW: Modifies a specified number of words

NCC: Modifying a specified number of rows

Delete command

NDW or NDW: Delete the n-1 characters at the beginning and after the cursor

Do: Delete to the beginning of the line

d$: Delete to end of line

NDD: Deletes the current line and its subsequent n-1 rows

X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the

Ctrl+u: Delete text entered under input mode

Search and Replace commands

/pattern: Searches for pattern at the end of the file from the beginning of the cursor

? pattern: Searches for pattern from the beginning of the cursor to the top of the file

N: Repeat the last search command in the same direction

N: Repeats the last search command in the opposite direction:

S/p1/p2/g: Replaces all P1 in the current row with P2:

N1,n2s/p1/p2/g: All P1 in line N1 to N2 are replaced with P2:

g/p1/s//p2/g: Replace all P1 in the file with P2

Option settings

All: List all option settings

Term: Set terminal type

Ignorance: ignoring case in search

List: Show tab stops (Ctrl+i) and end of line flags

($) Number: Show line numbers

Report: Displays the number modified by the line-oriented command

Terse: Displays a short warning message

Warn: Displays no when you go to another file without saving the current file

Write information

Nomagic: Allows the use of special characters that are not preceded by "\" In search mode

Nowrapscan: Prohibit VI from the other end when the search reaches the end of the file

MESG: Allow VI to display information that other users write to their terminal using write

Last line mode 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 below the N3 line

: n1,n2 d: Delete the contents of N1 rows to N2 rows

: w: Save current file

: E filename: Open file filename for editing

: x: Save current file and exit

: Q: Exit VI

: q!: Do not save file and Exit VI

:!command: Execute shell command

: n1,n2 W!command: The contents of the N1 line to the N2 line in the file are entered as command and executed, and if N1,N2 is not specified, the entire file content is entered as the command

: R!command: Puts the command's output to the current line.

    

First Knowledge VI Editor

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.