VI command usage

Source: Internet
Author: User
Start the visual editor vifilename from shell to instruct shell to start the vi editor and pass the filename parameter to it. If the current file exists, the vi editor interprets it as the file to be opened. if the file does not exist, the vi compiler creates a new file vifile1file2file3shell to pass three files.

Start the visual editor from shell
Vi filename indicates the shell to start the vi editor and pass the filename parameter to it. If the file exists, the vi editor interprets it as the file to be opened. if the file does not exist, the vi compiler creates a new file.
Vi file1 file2 file3 shell passes three parameters to vi, which is interpreted as the file to be opened by vi. You can run the w command to save the file and run the n command to access the next file.
Vi + # filename open the file and move the cursor to the specified row. For example, run the command vi + 100 records to edit the file records from line 3.
Vi +/the filename open the file and move the cursor to the row containing the target string. For example, the command vi +/Jason friends starts editing the file friends from 1st lines containing the string Jason.
View filename: open the file and edit it. However, the file cannot be modified unless w is used! Command
Cursor movement command
Hjkl moves the cursor to the left, bottom, top, and right of a character.
0 (zero) move the cursor to the beginning of the current row
^ Move the cursor to the beginning of the row like 0
$ Move the cursor to the end of the current row
# G move the cursor to the row specified by the number before G. For example, move the cursor to the 42nd rows of the file at 42 GB.
G move the cursor to the last line of the file
W move the cursor forward to the first letter of the next word
E move the cursor forward to the last letter of the next word
B. move the cursor backward to the first letter of a word.
-Move the cursor to the beginning of the last row.
+ Move the cursor to the beginning of the next row
12 | move the cursor to the 12th column of the current row
L move the cursor to the bottom line of the screen
M positions the cursor in the middle of the screen
H. move the cursor to the top line of the screen.
Two single quotes move the cursor to its previous position
Cursor location command (context)
Fb moves the cursor forward to the next letter B on the current row (or any other specified character)
Fb moves the cursor backward to the previous letter B (or specified character) on the current row)
T # Move the cursor to the right of the 1st instance of the character # on the current line. For example, the tM command moves the cursor to the right of 1st MB on the current line.
T # Move the cursor to the left of the current row and move it to the first character of the 1st instance of character #
/Word move the cursor forward to the next instance of word
? Word moves the cursor backward to the previous word instance
N move the cursor to the front command/word or? Next instance of the specified mode in word
Show adjustment command
Ctrl + D display the text in the lower half of the file
Ctrl + U display the upper half text in the file
Ctrl + F display the next screen text in the file
Ctrl + B display the previous text in the file
Set Display options
: Set number uses the row number as a part of the screen, but the row number is not part of the file. It is abbreviated as: set nu
: Set nonumber: Clear the row number on the screen. You can also use the abbreviation set nonu.
: Set showmode: displays append mode information in the lower right corner of the screen.
: Set list displays the dollar sign at the end of each row, and uses Ctrl + I to represent the tab
: When set showmatch is input) or], move the cursor to the matched (or [
: Set window = value defines the number of lines of text lines displayed on the screen
: Set autoindent: Auto Indent. You can also use the abbreviation set ai.
: Set tabstop = value: set the number of spaces that display tabs. You can also use the abbreviation ts = value.
: Set wrapmargin = value: set the right side of the display. When you enter the configured page edge, the editor automatically returns a line feed.
: Set ignorecase indicates that the editor searches for strings and ignores the uppercase and lowercase letters in the target.
: Set: displays all the settings.
: Set all: display all options that can be set
Text deletion command
Dd deletes all text lines of the current cursor
# Dd delete # line text
Dw deletes a word from the text
# Dw delete # words from text
X deletes a character from the cursor.
# X remove # Characters from text
D. delete the part after the cursor on the current row.
: #, # D for example,: 12, 37d will delete 12th ~ All text between 37 rows, including 12th and 37 rows
Undo command
U undo. Restore the last text modification operation, even if the cursor has been moved. In Linux, use the undo command again to restore the previous text modification operation. In BSD vi, the first undo operation will be abolished for 2nd undo operations, and the text modified before the first undo operation will be restored.
: Redo in Linux, cancel the undo operation to restore text modification. In standard UNIX systems, 2nd u commands cancel 1st u commands, and the result is a "redo"
U if the cursor has not been removed from the current row after modification, you can cancel all text modifications made to the current row.
Add text to text
A (lower case) inserts text from the right of the cursor
A (uppercase) adds text from the end of the current row
I (lower case) insert text from the left of the cursor
I (uppercase) insert text from the beginning of the current row
O (lower case) open (or insert) a new line under the cursor
O (uppercase) opens a new line above the cursor
: # R filename for example: 8r report. old reads the report. old file and places its content after the first row of the current file
No matter what commands are used to enter the Append/insert mode, you can press Esc to exit the append mode and return to the vi command mode.
Ctrl + V allows the input of control characters. Press Ctrl + V and press enter to insert Ctrl + M to the file.
Modify text in a file
Cw only modifies the word at the cursor (delete the word and enter append mode to add text at the position of the word to be deleted)
S (lower case) replace a single character
S (uppercase) replaces the entire line of text
Cc replaces the entire line of text (same as S)
R replaces the character at the current cursor with the next character entered, and automatically returns to the command mode
R place the editor in overwrite mode and replace the characters at the cursor one by one with the entered characters.
C (uppercase) modify the text between the cursor and the end of the line
Ct # modify the text on the row between the cursor and the first 1st target characters. For example, ctY deletes all text from the cursor to the first 1st characters Y on the current line, and enters the append mode to add text at the position of the deleted text
Cf # modify the text (including the target character) between the cursor and the first 1st target characters in a row ). For example, cfY deletes all text (including Y) between the cursor and the first 1st characters of Y on the current line, and enters the append mode to add text at the position of the deleted text
CT # modify the text between the cursor and the 1st target characters in the row. For example, cTY will delete all text on the current line from the cursor to the back of 1st characters Y, and enter the append mode to add text at the position of the deleted text
CF # modify the text (including the target character) between the cursor and the 1st target characters in the row ). For example, cFY deletes all text (including Y) from the cursor to the back of the current line, and enters the append mode to add text at the position of the deleted text

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.