Vim editor learning notes and vim learning notes
There are many text editors that can run in Linux. Different Linux distributions will certainly have built-in Vi editors, and other editors may not have built-in ones. You need to install them on your own. Therefore, you must learn how to use Vi in a new Linux environment. The Vim editor is an upgraded version of the Vi editor. It is more powerful than Vi and is compatible with Vi operations. So I learned the Vim editor directly. (This article only records my study notes and will be constantly supplemented and modified. please correct me if there is anything wrong)
The Vim editor has three modes: Command mode, insert mode, and command line mode. When Vim is enabled, enter the command mode. In this mode, you can move, delete, and copy the cursor"I, I, a, A, o, O, r, R"The eight commands enter the insert mode. In this mode, the text content is inserted and modified. Press ESC to exit the command mode.":,/,?"Enter the command line mode. In this mode, perform operations such as searching, replacing, saving, and releasing, and reading files. Press ESC to exit the command mode. The insert mode and command line mode cannot switch between each other. You can only switch out of the command mode.
1. Open, close, and save the file
1,Vim filename [...]
Enter the above command in Bash to open the file. Vim can be followed by multiple file names to open multiple files at the same time. If the filename file does not exist, a file named filename is created.
2. Press ":" to enter the command line mode.Q,W,!Three commands to save the file and exit.
: Q# Do not save the exit File
: Q!# Force exit (!Is forced to exit, does not require user confirmation)
: W# Saving files does not exit
: Wq# Save and exit
: Wq newfilename# Save As newfilename and exit
: N1, n2 w newfilename# Save the content from line n1 to line n2 of the file as a new file named newfilename
3. In command line mode,R,E"Two commands to open the new file.
: R filename# Append the content of filename to the end of the file being edited
: E filename# If no file is specified when you open the Vim editor, you can use this command to open the filename file for editing.
(To be continued)