Linux/unix VI Editor Usage detailed

Source: Internet
Author: User

The VI command is a common and important command under UNIX to edit one or more files in Full-screen mode. If you do not specify a file in VI, then the VI command will automatically generate a nameless empty working file. If the specified file does not exist, a new file is created by the specified file name. If changes to the file are not saved, the V I command does not change the contents of the original file.

Note: The VI command does not lock the file edited by the residence, so multiple users may edit a file at the same time, then the last saved version of the file will be retained.

Here are some of the options and meanings used by the VI command:

-C Sub-command Executes the specified command Sub-command before editing the specified file.

-r filename restores the specified file filename.

-R puts the specified file into the editor as read-only so that no modifications to the file are saved.

-Y number sets the editing window to the number row size.

The following are three modes of VI editing:

The mode at which the command mode enters VI. In this mode, users can enter various subcommand pairs for *, such as deleting rows, pasting rows, moving down a word, moving to different rows, and so on.

. text input mode in this mode, you can modify the contents of a row and add new lines. Type A, I, or C in command mode to enter the text input mode and press the escape key to return to command mode.

. Command entry mode in this mode, you can enter more parameters through the subcommand. For example, the W subcommand requires a file name to be entered, and the "/" subcommand requires a lookup entry. The user uses the Escape key to return to command mode.

The following are commands that are moved on the same line from the command mode:

H moves the cursor to the left one.

L MOVE the cursor to the right one grid.

J Move the cursor down one grid.

K Moves the cursor up one grid.

W moves the cursor to the front of the next small print.

W moves the cursor to the front of the next big font.

b move the cursor to the front of the previous small print.

B move the cursor to the front of the previous font.

E moves the cursor to the back of the next small print.

E moves the cursor to the back of the previous font.

FC moves the cursor to the next C character at the same line.

Fc moves the cursor to the previous C character in the same line.

TC moves the cursor to the previous grid in the next character C of the same line.

Tc moves the cursor to the back of the previous character C of the same line.

number| Move the cursor over the recursive number column.

The following are child commands that move between rows in command mode:

+ or ENTER to move the cursor to the first non-white-space character on the next line.

-Moves the cursor to the first non-white-space character on the previous line.

0 move the cursor to the first character of the current line.

$ moves the cursor to the last character in the current line.

H move the cursor to the top row of the screen.

L move the cursor to the bottom line of the screen.

M move the cursor to the middle of the screen.

Following is the command mode to change the display of the child command:

Z takes the current line as the last line on the screen and displays the screen again.

Z. Take the current row as the middle line of the screen and display the screen again.

CTRL+L Displays the current contents of the screen.

/pattern/z-looks for the next position in the pattern and sets the line to the last line on the screen.

The following are the child commands used to display the page in command mode:

Ctrl + F Roll back one page.

Ctrl + D Roll back half of the page.

Ctrl + B roll forward one page.

Ctrl + U roll forward half page.

Ctrl + E screen rolls down one line.

Ctrl + y screen items scroll up one line.

The following are the child commands used to find strings in command mode:

/pattern looks for the specified pattern backwards, and starts again if the end of the file is encountered.

? pattern looks forward to the specified pattern, and if the file header is encountered, start at the end.

N executes the last-defined lookup again in the direction that was last specified.

N performs the last-defined lookup again in the opposite direction of the last specified direction.

/pattern/+number stops the cursor on the number line after the line that contains the pattern.

/pattern/-number stops the cursor on the first number line before the line that contains pattern.

% to a matching "()" or "{}".

The following is a subcommand for entering text in text input mode (the user can return to command mode at any time by pressing escape):

A begins entering text after the cursor.

A begins entering text at the end of a line.

I start typing text before the cursor.

I enter text before the first non-white-space character at the beginning of the line.

o Inserts a blank line after the line where the cursor is located.

o Inserts a blank line before the cursor is row.

The following is a subcommand used to change the text in command mode (the user can press the escape key to return to command mode at any time):

CC or S modifies an entire line.

C changes the portion of the cursor position after a row.

The CW changes the word at the cursor.

DD deletes the current line.

D deletes the contents of the cursor behind the row cursor.

DW Deletes the word where the cursor is located.

J Add the next line to the end of the bank.

RC replaces the character of the light symbol with C.

R covers the contents of the bank.

U revert to last modification.

x deletes the character where the cursor is located.

~ Change the case of the character on which the cursor is located.

. Repeat the previous *.

<< move the current row to the left.

>> move the current line to the right.

The following is a word command for copying text in a file:

P takes the buffer contents to the line below where the cursor is located.

P takes the buffer contents to the line above the row on which the cursor is located.

"BD deletes text to a named buffer B.

"BP posted the contents of a named buffer B."

YY puts the current line into the buffer.

Y puts the current line into the buffer.

YW puts the word of the cursor in the buffer.

: g// D, delete all matching rows

The following are the child commands used to save the file:

: W write back the modified file.

: w filename when filename does not exist, the modified file saved as file filename, when the file filename exists, the error.

!w filename If file filename exists, save the modified file as file filename.

The following is a list of the child commands that are used to toggle between multiple files edited by VI:

: N to begin editing the next file in the vi-activated file list.

: N filenames specifies a new list of files to be edited.

The following is a list of child commands for switching between the current file and another file:

: E filename is used to activate VI (in the vi loaded another file filename).

e! the current file and discard previous changes if the current file is changed.

: E+filename uses filename to activate VI, and starts editing from the end of the file.

: e+number filename activates VI with filename and starts editing at number line.

: e# begins editing another file.

The following is a subcommand used to add additional file code to this file:

: R filename reads the filename file and adds its contents to the current file.

: R! command executes the command file and adds its output to the current file.

Here are the other sub commands in VI:

Ctrl+g to obtain information about the file being edited.

: SH start sh, return available exit or ctrl+d from SH.

:! command to execute commands.

!! Re-executing the last:! Command subcommand.

: Q Exit VI, if the user to edit the file has been modified, the system will not let users use the Q command to exit.

: q! Exit VI Regardless of whether there are changes to the file.

ZZ OR: Wq Save the changes to the file and Exit VI.

Users can define special VI commands in a special file. Exrc. When you use these commands in VI, you must precede the command with a colon (:).

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.