In the Linux system, VI Editor is a powerful and efficient text editing tool, which is widely used in program development, configuration file editing and other scenarios. This article will give you an in-depth understanding of the use of vi commands, so that you can become more proficient in text editing in the Linux environment.
1.Open File: The command to open a file using the vi editor is vi filename. If the file does not exist, a new file will be createdIf the file already exists, it will be opened directly.
2.Common modes:
Normal Mode: The default mode, which is used for basic operations such as moving the cursor, copying, pasting, etc.
Insert mode: Press the I key to enter the insert mode, where you can edit the text.
Command-line mode: Press the : key to enter command-line mode, perform advanced operations such as saving and exiting.
3.Common Operations:
Move the cursor: Use h, j, k, and l to indicate left, bottom, up, and right, respectively.
Copy-paste: Copy a row with yy in normal mode, p paste.
Undo Redo: In normal mode, press u to undo, and ctrl + r to redo.
4.Save and Exit:
In normal mode, type: w to save the file.
Input: q to exit the vi editor.
Input: wq to save and exit.
Input: q!Force quit without saving the changes.
5.Advanced features:
Search and replace: In normal mode, enter keyword to search, type: s old text new text g to replace.
Line Number Jump**In normal mode, enter the line number plus g to jump to the specified line.
With this article, you should now have a deeper understanding of the basic usage and advanced features of the VI editor. Proficiency in the use of vi commands will enable you to edit text more efficiently and improve your work efficiency under the Linux system. Remember to use in normal mode :q!Be cautious when commanding to avoid losing unsaved modifications. Hopefully, this guide will be helpful when using the VI editor on your Linux system.