Write in front: the blogger is a real combat development after training into the cause of the “hill pig”, nickname from the cartoon “Lion King” in “Peng Peng”, always optimistic, positive attitude towards things around. My technical path from Java full stack engineer all the way to big data development, data mining field, now there are small achievements, I would like to share with you what I have learned in the past, I hope to help you on the way of learning. At the same time, the blogger also wants to build a perfect technical library through this attempt. Any anomalies, errors and matters needing attention related to the technical points of the article will be listed at the end, and everyone is welcome to provide materials in various ways.

  • Please criticize any mistakes in the article and revise them in time.
  • If you have any questions you would like to discuss or learn, please contact me at [email protected].
  • The style of the published article varies from column to column, and all are self-contained. Please correct the deficiencies.

Linux text editing tool – vi

Keywords: text editing, VI, normal mode, edit mode, command mode \

The article directories

I. VI working mode

Due to the “configure everything” nature of Linux, we often have to modify the configuration files of various software and services, so mastering the basic editing tools is essential. On a Linux desktop, you can use tools like Gedit to edit the contents of a file as if you were using Notepad. But in a production environment, we often need to connect to a machine remotely, all in command mode, and the server itself may not have a desktop installed.

  • Common mode: Enter the default mode when you open a file using the vi command. You can move the cursor and perform shortcut keys.
  • Edit mode: You can switch from the common mode to move the cursor and modify the text.
  • Command mode: This mode is used to search, replace, save, and exit.

The editing mode and command mode use common mode as the middle working mode. Before switching between them, you need to switch back to the common mode first, and press ESC to switch back to the common mode. To enter the editing mode from the common mode, you can create a line by using I/A or O. To enter the command mode from the common mode, you can exit the VI tool from the command mode by using a colon (:).

Second, cursor operation

In the VI tool, you can use arrow keys or corresponding letters to move the cursor. However, you can only move one line at a time. Shortcuts are required for efficient operation.

  • Display the line number -> In command mode: set nu
  • Hide line number -> In command mode: set nonu
  • Go to line N -> command mode: n

Third, document editing

There are two ways to use the VI tool to edit a document. One is to directly enter the editing mode to modify the file content, and the other is to use the shortcut keys to delete and copy the file in the basic unit of behavior in the common mode.

Find replacements

For text editing, the search and replace function is also indispensable. In command mode, text content can be searched and replaced according to the specified format.

5. Save and exit



For beginners, save exit is a big problem, I believe all experienced the following scenarios:

Because of the various modes are not familiar, under the crazy keyboard found suddenly enter the edit mode, the content of the file has been unexpectedly modified, at this time the first question that comes to mind is how to exit the file without saving, the following is to demonstrate.



There are two ways to save files

  • To quickly save, type ZZ in normal mode: that is, hold Shift and press z twice
  • Using the w command in command mode can be used in conjunction with exit or to perform operations like save as

\