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

What are the ways to use the linux vi editor

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what is the use of the linux vi editor?" in the operation of actual cases, many people will encounter such a dilemma, 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 linux vi editor is the standard editor for all Unix and Linux systems. It is as powerful as any text editor. Here is a brief introduction to its usage and a small number of instructions. Since the linux vi editor is exactly the same for any version of Unix and Linux systems, you can learn more about it anywhere else that introduces vi. Vi is also the most basic text editor in Linux, and after learning it, you will walk freely in the world of Linux.

1. The basic concept of vi

Basically, vi can be divided into three states: command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

1) Command line mode command mode)

Control the movement of the screen cursor, the deletion of characters, words or lines, move and copy a section and enter the Insert mode, or to the last line mode.

2) insert mode (Insert mode)

Text input can only be done under Insert mode, and press the "ESC" key to return to command line mode.

3) bottom line mode (last line mode)

To save or exit vi, you can also set the editing environment, such as finding strings, listing line numbers, etc. Wait.

However, when we use vi, we usually simplify it into two modes, that is, the last line mode mode is also included in the command line mode command mode).

2. Basic operation of vi

A) enter vi

After the system prompts for the symbol vi and the file name, go to the vi full screen editing screen:

$vi myfile

It is important to note, however, that after you enter vi, you are in "command line mode (command mode)", and you have to switch to "insert mode (Insert mode)" before you can enter text. People who use vi for the first time will want to use the upper and lower keys to move the cursor first, and as a result, the computer beeps all the time, making themselves angry half to death, so after entering the vi, don't move, switch to "insert mode (Insert mode)".

B) switch to insert mode (Insert mode) to edit the file

Press the letter "I" in "command line mode (command mode)" to enter "insert mode (Insert mode)" and you can start typing text.

C) switching of Insert

You are currently in Insert mode mode, so you can only type text all the time if you find that you have typed the wrong word! To use the cursor key to move back and delete the word, press the "ESC" key to go to "command line mode (command mode)" before deleting the text.

D) exit vi and save the file

Under Command Line Mode (command mode), click the: colon key to enter Last line mode, for example:

W filename (enter "w filename" to save the article with the specified file name filename)

: wq (enter "wq", save and exit vi)

: q! (enter qquit, do not save the disk and force to exit vi)

3. Command line mode (command mode) function key

1)。 Insert mode

Press "I" to switch to insert mode "insert mode". Press "I" to enter the file from the current position of the cursor after entering insert mode

After pressing "a" to enter insert mode, the text is entered from the next position where the current cursor is located.

When you press "o" to enter insert mode, insert a new line and enter text at the beginning of the line.

2)。 Switch from insert mode to command line mode

Press the ESC key.

3)。 Move the cursor

Vi can directly use the cursor on the keyboard to move up and down, but the regular vi uses lowercase letters "h", "j", "k" and "l" to control the cursor to move left, down, up and right respectively.

Press "ctrl" + "b": move the screen one page back.

Press "ctrl" + "f": the screen moves one page forward.

Press "ctrl" + "u": move the screen to "back" half a page.

Press "ctrl" + "d": move the screen half a page to the front.

Press the number "0": move to the beginning of the article.

Press "G": move to the * * of the article.

Press "$": move to the end of the line where the cursor is located.

Press "^": move to the beginning of the line where the cursor is located

Press "w": the cursor jumps to the beginning of the next word

Press "e": the cursor jumps to the suffix of the next word

Press "b": the cursor goes back to the beginning of the previous word

Press "# l": move the cursor to the # th position on the line, for example: 5lMagne56l

This is the end of the content of "how to use the linux 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