VI (Vim) Description/illustration

Source: Internet
Author: User
Tags add numbers line editor

[Syntax]: VI [-wn] [-R] file...
[Note]: VI is a full-screen editor based on the line editor ex. All commands of ex and Ed can be used in VI, in the VI option, "-WN" indicates that the size of the editing window is set to N rows, and "-R" indicates that the edited file is set to read-only. The vi working mode is divided into command mode and input mode, in command mode, you can enter the VI command and edit the text to be edited when entering input mode, the command a I I o C S R can enter the input mode. In the input mode, Press ESC to bring the input mode back to the command mode. In the command mode, enter: command, you can enter the ex mode, a prompt appears at the bottom of the screen:, you can use any ex command, the bottom line of the screen is also used/
? ! Command Prompt line. Most commands can be preceded by a number, indicating the number of times the command is repeated. The following briefly introduces the VI command set, ^ represents (CTRL) Key.
^ B returns to the previous page. Adding a number to the previous page indicates the number of duplicates.
Retain the two rows of the previous page
^ D in command mode, it indicates half of the rolling screen. In input mode, it indicates rolling back
Auto indent on the left
^ E display the line below the screen bottom line
^ F indicates the number of duplicates on the previous page.
Retain the two rows of the previous page
^ G: displays the current file name, the current row number, and the total number of lines of the file.
Location in the entire file
^ H (unspace) in command mode, the cursor moves one cell to the left; in input mode, delete the previous character
^ I (Tab) generates a string of spaces in input mode.
^ J (LF) move the cursor down a row
^ L refresh the screen to re-display the screen
^ M (Press ENTER) in command mode, move the cursor to the beginning of the downstream
Open up a new line in input mode
^ N move the cursor down a row
^ P move the cursor up a row
^ In input mode, Q inserts the non-printable character after it into the body.
^ R refresh the screen
^ U the screen is rolled in half. Adding a number in front of the screen indicates the number of rows to be rolled up.
The subsequent ^ d ^ U command is valid.
^ V in input mode, insert the non-printable character after it as the body
^ W enables the cursor to return a word in input mode
^ Y displays the line above the screen bottom line
^ Z pause editing and return to the Upper Shell
^ [(ESC) Exit input mode and return to command mode
! Temporarily exit editing and execute shell commands
Double quotation marks (double quotation marks) are used to mark the famous buffer, and serial number buffer 1-9 is used to save the deleted body, word
The parent name buffer zone A-Z is used to store the custom body.
$ Move the cursor to the end of the current row. Adding a number before the cursor indicates moving the row forward, for example, 2 $ indicates moving
To the end of the next row
% Move the cursor to the paired parentheses () or braces {}
(Return the beginning of the sentence
) Forward to the beginning of a sentence
-Return to the first non-space character in the previous line
. Repeat the last command to change the buffer content
/Mode: Forward search mode. move the cursor to the appearance of the mode. The mode is a regular
Expression (see grep)
: At the bottom of the screen, you can use the ex command.
? The function is the same as/, but the direction is forward lookup.
[[Move the cursor back to the boundary of the previous section
Specifier
] Move cursor forward to the section boundary
^ (Not CTRL) move the cursor to the first non-empty character in the current row
'Two consecutive ''' indicates that the cursor is moved to the position before it is moved, 'followed by a letter indicates the cursor word
The beginning of the line marked by the mother (refer to the M command)
A inserts the body at the end of a row into the input mode.
B. move the cursor back to a word.
C. Content after replacing the cursor
D. Delete the content after the cursor.
E move the cursor to the end
The F character searches for the specified character on the left of the current line.
G move the cursor to the row specified by the number before it, and move to the last row if not specified
H move the cursor to the top line of the screen. If there is a number in front, move it to the number on the screen.
Specified row
I insert the body at the beginning of a row
J connects two rows. If there is a number in front, the row specified by the number is connected.
L move the cursor to the bottom line of the screen. If there is a number in front, move the cursor to the bottom line of the screen to count this
Row specified by number
M move the cursor to the midline of the screen
N use mode lookup/or? Find the next matching pattern again, but the direction is consistent with the previous
N, but in the opposite direction.
O open up a new line on the current line
P inserts the last deleted body into the front of the cursor. You can add a buffer number before it to compile
1-9 is used to save the deleted body. The letter name buffer zone A-Z is used for user-defined storage.
Text
Q from VI to the ex command status
R replacement string
S replaces the entire line
T character to search for characters on the left
U restores the current row to the status before the first modification
W move cursor to the next beginning
X Delete the character before the cursor
Y saves the current row to the Untitled buffer zone. The preceding number indicates the number of rows to be saved.
Name Buffer to save. You can use the command P or P to retrieve it later.
Log on to the ZZ disk and exit VI.
Insert body after a cursor
B. move the cursor back to the beginning.
CW replaces the current word
C) Replace the current sentence
DW deletes a word
Dd deletes a row
E move the cursor to the end of the next word
The F character looks forward to the current row.
H move the cursor to the left
I insert the body before the cursor
J move the cursor down a row
K move the cursor up a row
L move the cursor one cell to the right
The M letter marks the current row with a letter. In the future, use the 'letter to move the cursor to the current row,
(Refer to the 'COMMAND)
N repeat the previous // or? Command
O open up a new line under the current row
P place the user buffer content at the cursor position (see the p command)
R replaces the current character
S replaces the current character with a string of characters
T character cursor move to before character
U cancels the last operation
W move the cursor to the next line
X Delete the current character
YW saves the current word to the unnamed buffer zone. The preceding value can be X, which indicates that the name of X is saved.
The buffer zone (X is a-z). You can add numbers to indicate the number of words stored in the buffer. In the future, you can use P or P.
Retrieve
YY saves the current row to the unknown buffer. For usage, see YW
{Move the cursor to the beginning of the previous paragraph
| Move the cursor to the beginning of the row. If a number is added to the front of the row, move it to the beginning of the row specified by the number.
} Move the cursor to the beginning of the next section.
At the prompt, Common commands are as follows:
: W current file storage disk
: W! Forced disk storage
: W file writes content to the specified file
: W! File forced write to the specified file
: X, y w file writes lines X to Y to the specified file
: R file reads the file to the cursor position
: R! Command to read the output of the system command to the cursor position
: Q: Exit editing.
: Q! Force exit
: X is the same as the command ZZ.
: E file name Edit another file
: E! Re-edit the file and discard any changes
: Sh, execute SH, and return to edit
:! Run the command and return to edit
: N: edit the next file
: N file table redefinition file table to be edited
: Set sets VI options. For example, set nu indicates that the row number is displayed before each row.
If no is added, this option is cleared. For example, set Nonu indicates that the row is not displayed before each row.
And the following are some common options:
Automatic AI indent
Aw automatically saves the disk before editing the next file
The IC is case insensitive when searching strings.
Nu displays the row number before each row
SM input) and} are matched (or {
Delayed screen refresh during slow insertion
WS enables searching to bypass the end of a file and start from the beginning
Wa does not check the file before writing it.

========================================================== ======================================

Visual is a visual-oriented full-screen editor. There are three methods ):
Command mode:
Any input will be used as an editing command and will not appear on the screen. If the input is incorrect, there will be a "" sound; any input


Both cause immediate response
Insert method:
Any input data is placed in the edit register. Input (I, a, a, and so on) in the command mode to enter the insert mode. Press ESC in the insert mode to switch back to the command mode.
Escape mode:
A command with ":" or "/" as the leading line appears at the bottom of the screen. Any input is considered as a special command.
Go to VI (enter the following command at the system prompt ):
VI enters VI without reading any files
VI filename: Enter VI and read the file with the specified name (both new and old files can be used ).
Vi + N filename enters VI and starts from the first line of the file.
Vi + filename enters VI and starts from the last line of the file.
Vi +/word filename enters VI and starts with the word of the file.
VI filename (s) enters VI and lists the specified files. The first file is read first.
Vedit enters VI and "insert mode" is displayed in the status line when the input mode is used ".
Edit several files (after entering VI using vi filename (s)
: ARGs displays the file names in the editing list.
: N: Read the next file in the editing list.
: Rew reads the first file in the editing list
: E # Read the previous file in the editing list
: E file: Read another file into VI (this file may not be in the editing list). If the original file has not been archived after modification, archive it with W.
: E! File forces reading another file into VI. The original file is not archived.
Storage and exit vi
: W filename is saved to the specified file, but VI is not exited (if no file name is specified, it is the currently working file name ).
: WQ or: X or ZZ to save the file and exit VI.
: Q does not make any changes and exits VI.
: Q! Discard any modifications and exit VI.
:! Command temporarily exits VI and executes shell commands. After the command is executed, return to VI.
: Sh temporarily exits VI to the system. Press Ctrl + D at the end to return to VI.
Add data commands
I start to insert characters at the mark-off position, and Press ESC at the end.
I start to fill in at the beginning of the row where the cursor is located, and Press ESC at the end.
A starts to add words after the cursor position. Press ESC at the end.
A starts to add words at the end of the row where the cursor is located. Press ESC at the end.
O add a blank line under the cursor and start to add words. Press ESC at the end.
O add a blank line to the cursor and start adding the word. Press ESC at the end.
! Command executes the shell command and adds the result to the next line in the row where the cursor is located.
DELETE command
NX deletes n characters starting from the cursor position (including the cursor position, and deletes the character of the cursor by X)
NX deletes n characters starting from the cursor position (excluding the cursor position ).
Ndw deletes the N character groups (Word) at the cursor position ).
D0 deletes all the characters starting from the row to the cursor position.
D $ or D Delete All characters starting from the cursor position to the end of the line.
NDD deletes n rows (whole row) starting from the cursor position (DD indicates deleting the row where the cursor is located ).
: Start, endd Delete the start-to-end row of the object.
Mark moving
0: Move to the beginning of a row
$ Move to the end of a row
[Move to the start position of the file
] Move to the end of the file
NH shifts n places to the left
NL or spacebar shifts n places to the right
NK moves n rows up
N + shifts n rows up, And the cursor starts at the beginning of the row
Ni moves n rows down
N-move n rows downward, cursor at the beginning of the row
H move to the upper left corner of the screen
M moves to the beginning of the middle line of the screen
L move to the last line of the screen
G move to the last row of the file
NG or: N moves to the nth row of the file.
NW shifts N word groups to the right. punctuation marks belong to word groups.
NW shifts N word groups to the right. The punctuation marks do not belong to the word group.
N word groups are moved to the left, and punctuation marks belong to word groups.
N word groups are moved to the left, and punctuation marks do not belong to the word group.
CTRL + u scroll menu on the screen
CTRL + D. Half menu on the screen
CTRL + B roll a menu on the screen
CTRL + F. A menu is available under the screen.
Modify command
R modify the character of the cursor file
R changes from the cursor position. Press ESC at the end.
New: Change N groups of characters. Press ESC at the end.
NCC changes n rows from the cursor position, and Press ESC at the end
Rearrange the length of each row
I and press enter to disconnect the line from the cursor and enter the insert mode
J. After connecting the data in the next row to the current row
Search for commands
/Text: Find the string text from the cursor position
? Text searches for the string text from the cursor position
N continue to find the next string (used after entering the SEARCH Command above)
Find and replace commands
: Getxt1/S // text2/options replace text1 of each row with text2
Option = G indicates that all the text1 files are replaced. If no option is entered, only the first text1 in each row is replaced.
Option = go display the replaced rows on the screen
Option = GC requires confirmation before each string is replaced
Start, endgtext1/S // text2/options are the same as above, and only the start ~ End line.
Or: Start, ends/text1/text2/options
Copy and move files
: First, last co dest: copy the data from the first row to the last row to the target row (DEST ).
: Start, end m dest move the data from start to end row to the target row (DEST.
: R filename: reads the content of the specified file into the row where the cursor is located.
NY saves n rows of data starting from the cursor position
P copies the saved data in the next row of the cursor.
P copies the temporary data row on the top of the cursor.
Other commands
. Repeat the previous command
U cancels the previous command
CTRL + L refresh the screen
: Set number: displays the row number of the file, but does not store the file
: Set nonumber remove row number display
: Set AI to set the starting position of each line (starting with the current position of the cursor)
: Set noai to cancel row start position setting
: F or <Ctrl> + G tells the user about the data of the current edited file. ========================================================== ======================================

Last line mode:
/EXP go forward to exp
? Exp go backward to exp


: W write buffer to disk
: W newfile write buffer to newfile
: W! File write absolutely
: Q quit Editor
: Q! Quit, discarding Buffer
: WQ write buffer and quit
Write if needed & quit
: F edit & File status
: R read file into Buffer
: R File Read named file in
: E (re) edit file
: E! (Re) edit, discard file in
: E file edit nameed File
: 3, 8D Delete lines 3-8
: 4, 9 M 12 move lines 4-9 to 12
: 2, 5 T 13 copy lines 2-5 to 13
: 5, 9 W file write lines 5-9 to file
: S/old/new/current line, sub first "old" W/"new"
: S/old/new/g current line, sub each "old" W/"new"
: 3, 9 S/old/new lines 3-9, sub first "old" W/"new"
: % S/old/new all lines, sub first "old" W/"new"
: % S/old/new/g all lines, sub each "old" W/"new"
: S/Pat./new A. Matches any charcter
: S/PAT */new A * matches 0 or more "T" s
: S/PA [0-9aeioa-z]/new selection set or range
: S/PA [^ aeiou]/New match any non-Vowel
: S/^ pat/new anchor "par" to beginning of Line
: S/pats/new anchor "par" to end of line
: S/old/& and new/restoe matched pattern on sub
: % S/./&/indenta whoIe File
: Set nu display line numbers
: Set Nonu turn off Option
: Set all show all settings
: Set list try to display invisible chars
: Set WM = 5 wrap lines 5 sp from R margin

Command mode:
<-|->
Hljk cursor Movement
G goto last file line
3G goto line 3
0 goto line start
$ Goto Line End
% Goto matching brace/Paren
H goto screen top
M goto screen middle
L goto screen bottom
W go forward 1 word
3 w go forward 3 word
B go back 1 word
3b go back 3 word
N repeat previous search
N reverse previous search
X delete one character
DW delete one word
Dd delete one line
D Delete to end of line
D0 Delete to beginning of Line
DG Delete to end of File
4dd Delete 4 lines
U undo last change
. Do Last Chang
Y yank a copy of a line
5y yank a copy of 5 lines
P put below cursor
P put above cursor
J join next line to current
4j join 4 lines to current
> Shift a line right
3> Shift 3 lines right
^ D 1/2 scroll forward
^ U 1/2 scroll backwards
^ F scroll forward
^ B scroll backwards
N repeat previous search
N reverse previous search
ZZ write if needed & quit vi

Insert mode:
A append after cursor
A append at line end
CW change a word
3cw change 3 words
C Change line
I insert before cursor
5I Insert at 5 times
I insert at beginning of Line
O open a linebelow cursor
O open a line above cursor
R replace one character
R replace/type-cver a line
S substitute a character
S substitue a line

Related Article

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.