Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of linux/unix vi editor

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "the use of linux/unix vi Editor". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The vi command is a common and important command under unix, which can edit one or more files in full-screen mode. If no file is specified when vi is executed, the vi command automatically produces an unnamed, empty working file. If the specified file does not exist, a new file is created with the specified file name. The v I command does not change the contents of the original file if the changes to the file are not saved.

Note: the vi command does not lock home-edited files, so multiple users may be editing a file at the same time, and the last saved version of the file will be retained.

Here are some of the options and implications used by the vi command:

-c sub-command executes the specified command sub-command. C before editing the specified file.

-r filename restores the specified file filename.

-R places the specified file in the editor as read-only, so that any changes to the file are not saved.

-y number sets the size of the editing window to the number line.

Here are three modes for vi editing:

. The mode in which the command mode enters vi. In this mode, the user can enter various sub-commands to perform * actions, such as deleting lines, pasting lines, moving to the next word, moving to different lines, and so on.

. Text input mode allows you to modify the contents of a line and add new lines. Type a, I, or c in command mode to enter text input mode, and press Escape to return to command mode.

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

The following are self-commands that are executed from command mode and moved on the same line:

H moves the cursor one grid to the left.

Move the cursor one square to the right.

J move the cursor down one grid.

K moves the cursor up one grid.

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

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

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

B move the cursor to the front of the previous big word.

E move the cursor after the next small print.

E move the cursor to the back of the previous big word.

Fc moves the cursor to the next c character on the same line.

Fc moves the cursor to the previous c character on the same line.

Tc moves the cursor to the space before the next character c on the same line.

Tc moves the cursor to the space after the character c on the same line.

Number | move the cursor over the passing number column.

Here are the subcommands that move between lines in command mode:

+ or Enter moves the cursor to the first non-white space character on the next line.

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

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

Move the cursor to the last character of the current line.

H moves the cursor to the top line of the screen.

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

M moves the cursor to the middle of the screen.

Here are the subcommands to change the screen display in command mode:

Z-takes the current line as the last line of the screen and redisplays the screen.

z. Take the current line as the middle line of the screen and redisplay the screen.

Ctrl+l redisplays the current contents of the screen.

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

Here are the subcommands used to display the page in command mode:

Ctrl + f scroll back one page.

Ctrl + d scroll back half a page.

Ctrl + b scroll forward one page.

Ctrl + u scroll forward half a page.

The Ctrl + e screen scrolls down one line.

Scroll one line on the Ctrl + y screen item.

Here are the subcommands used to find strings in command mode:

/ pattern looks back for the specified pattern, and if it encounters the end of the file, it starts from scratch.

? Pattern looks forward for the specified pattern, and if it encounters the header of the file, it starts at the end.

N performs the last defined lookup again in the last specified direction.

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

/ pattern/+number pauses the cursor over the number line after the line that contains pattern.

/ pattern/-number pauses the cursor over the number in front of the line that contains pattern.

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

Here are the subcommands used to enter text in text input mode (the user can press Escape to return to command mode at any time):

A start entering text after the cursor.

An enter text at the end of the line.

I start entering text before the cursor.

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

O insert a blank line after the line of the cursor.

O insert a blank line before the line where the cursor is located.

Here are the subcommands used to change the text in command mode (the user can press Escape at any time to return to command mode):

Cc or S modifies an entire line.

C the part after changing the cursor position of a line.

Cw changes the word where the cursor is located.

Dd deletes the current line.

D deletes the content behind the cursor on the line where the cursor is located.

Dw deletes the word where the cursor is located.

J adds the next line to the end of the line.

Rc replaces the character of the light character with c.

R overrides the content of this line.

U restores the last modification.

X deletes the character where the cursor is located.

~ change the case of the outgoing character where the cursor is located.

. Repeat the previous * action.

Move the current line to the right.

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

P takes the contents of the buffer to the line below the cursor.

P fetches the contents of the buffer to the line above the cursor.

"bd deletes the text to the named buffer b.

"bp posts the contents of the named buffer b.

Yy puts the current line in the buffer.

Y places the current line in the buffer.

Yw places the word where the cursor is located in the buffer.

: GUniPure d, delete all lines that match

Here are the subcommands to save the file:

: W write back the modified file.

W filename when filename does not exist, save the modified file as a file filename, and report an error when the file filename exists.

! W filename if the file filename exists, save the modified file as the file filename.

The subcommands used to switch between multiple files edited by vi are listed below:

: n starts editing the next file in the list of files activated by vi.

: n filenames specifies the new list of files to be edited.

The subcommands used to switch between the current file and another file are listed below:

: e filename activates vi using filename (loads another file, filename, in vi).

E! Reload the current file and discard the previous changes if there are any changes in the current file.

E+filename activates vi using filename and edits from the end of the file.

: e+number filename activates vi using filename and starts editing at line number.

: e# starts editing another file.

Here are the subcommands used to add other 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 subcommands in vi:

Ctrl+g gets information about the file being edited.

Sh starts sh and returns available exit or ctrl+d from sh.

:! Command executes the command command.

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

: Q exit vi. If the user modifies the edited file, the system will not allow the user to exit using the Q command.

: q! Exit vi regardless of whether or not there are changes to the file.

ZZ or: wq saves changes to the file and exits vi.

You can define a special vi command in a special file. Exrc. When using these commands in vi, you must precede the command with a colon (:)

This is the end of the introduction to the usage of linux/unix vi Editor. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report