This is the third day of my participation in the August More text Challenge. For details, see: August More Text Challenge

A lifelong learner, practitioner, and sharer committed to the path of technology, an original blogger who is busy and sometimes lazy, and a teenager who is occasionally boring and sometimes humorous.

Welcome to search “Jge’s IT Journey” on wechat!

Common vi/vim editor commands in Linux

preface

Use the VI text editor

Configuration files are one of the distinguishing features of Linux systems. They function a bit like the registry in Windows systems, except that the registry is centrally managed, while configuration files are managed in a decentralized manner. How to use vi, the text editor in the Linux character Manipulation interface, to better manage and maintain the various configuration files in the system.

Vi is a powerful full-screen text editor that has long been the default text editor for UniX-like operating systems. Vim is an enhanced version of the VI editor that extends many useful features of the vi editor, but is also conventionally referred to as vi.

I. Use of vi/ VIm

Vi is a full-screen editor working in the character terminal environment, so the editing interface is relatively simple. It does not provide mouse operation and menu system for users, but realizes corresponding editing and operation functions through key commands. You can use three different working modes on the VI editing interface. There are Command mode, Insert mode, and Last line mode. Of course, what you can do to the file varies in different modes.

1.1 Command Mode

The user starts vi/vim and enters the command mode.

Keystrokes in this state are recognized by Vim as commands, not as input characters. For example, if we press I, instead of typing a character, I is treated as a command.

Here are some common commands:

  • I Switches to input mode to enter characters.
  • X Deletes the character where the cursor is located.
  • : Switches to the bottom-line command mode to enter the command on the bottom line.

To edit text: Start Vim, enter command mode, press I to switch to input mode.

The command mode has only the most basic commands, so you still have to rely on the bottom-line command mode to enter more commands.

1.2 Input Mode

Press I in command mode to enter input mode.

In input mode, the following keys can be used:

  • Character key and Shift combination, enter character
  • ENTER, ENTER key, newline
  • The BACK SPACE key removes the character before the cursor
  • DEL, delete key, delete one character after the cursor
  • Arrow keys to move the cursor through the text
  • HOME/END, move the cursor to the beginning /END of the line
  • Page Up/ Down
  • Insert, switch the cursor to input/replace mode, the cursor will become a vertical line/underline
  • ESC: Exit the input mode and switch to the command mode

1.3 Last-line mode

Press (Colon) in command mode to enter the last-line mode.

The last-line mode allows you to enter single or multi-character commands, and there are many commands available.

In the bottom-line command mode, the basic commands are (colons have been omitted) :

  • Q Exit program
  • W Save file

Press ESC key to exit last line mode at any time.

In short, these three patterns can be expressed in the following flow chart:

Ii. Description of vi/ VIM buttons

In the command mode of the VI editor, you can enter specific keys (called vi operation commands, which are different from Linux commands) to perform operations. The operations include mode switching, cursor movement, copy, delete, paste, file content search, save, and exit.

Third, basic operations in the last line mode

Press the colon (:) key in the command mode to switch to the last-line mode. The last-line prompt (:) is displayed on the last line of the VI editor. You can enter the last-line command after the prompt to save the file and exit the editor.

Recommended reading

99% of Linux operation and maintenance engineers must master the command and use

Common commands of the Oracle database in Linux

In this paper, to the end.


Original is not easy, if you think this article is a little useful to you, please give me a like, comment or forward for this article, because this will be my power to output more quality articles, thanks!

By the way, dig friends remember to give me a free attention yo! In case you get lost and you can’t find me next time.

See you next time!