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

Text Editing tool under Linux-vi

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

Share

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

Text Editing tool under Linux-vi

Text keywords: text editing, vi, normal mode, editing mode, command mode

I. vi working mode

Because of the "everything is configured" feature of the Linux system, we often have to modify the configuration files of various software and services, so it is necessary to master the most basic editing tools. In Linux systems with desktops, we can use tools such as gedit to edit the contents of the file directly like notepad. But in a production environment, we usually need to connect remotely to a machine, all in command mode, and the server itself may not have a desktop installed.

Normal mode: the mode that you enter by default when you open a file using the vi command, which allows you to move the cursor and shortcut keys. Edit mode: can be switched by the normal mode, move the cursor, modify the text content. Command mode: can be switched by the normal mode, used to perform search, replace, save exit and other operations.

Both the editing mode and the command mode take the normal mode as the middle working mode. When switching to each other, we need to return to the normal mode first, and use the ESC key to return to the normal mode. From normal mode to edit mode, you can use iUnip an or o to directly create a new line, from normal mode to command mode use colons, and you can exit the vi tool from command mode.

2. Cursor operation

Use arrow keys or corresponding letters to operate the cursor in the vi tool, but usually you can only move one line at a time, so you need to use the corresponding shortcut keys when you need efficient operations.

Show line number-> command mode: set nu hide line number-> command mode: set nonu navigate to line n-> command mode: n

III. Document editing

When using vi tool for document editing, there are two ways, one is to directly enter the editing mode to modify the contents of the file, and the other is to use shortcut keys to delete and copy the basic units of line bits in ordinary mode.

Fourth, find and replace

For text editing, it is also necessary to find and replace the text. In the command mode, the text content can be found and replaced according to the specified format.

5. Save and exit

Saving exit is a big problem for beginners. I believe they have experienced the following scenarios:

Because I am not familiar with various modes, I found that I suddenly entered the editing mode under the keystroke, and the content of the file has been unexpectedly modified. The first question that comes to mind at this time is how to exit this file without saving. Here's a demonstration.

There are two ways to save a file

Type ZZ in normal mode to save quickly: that is, hold down Shift and press the letter z twice to use the w command in command mode, you can use it with exit or perform operations similar to save as

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