Article directory
1. Basic introduction
The Linux system will have a built-in Vi text editor. Vim has the ability of program editing, which can be regarded as an enhanced version of VI. It can actively use font colors to identify the correctness of grammar, which is convenient for program design. Code completion, compilation, and errors are particularly rich in programming-friendly functions, and are widely used among programmers.
Two, common mode
2.1 Normal Mode
Opening a file with Vim directly enters the normal mode (this is the default mode). In this mode, you can use the [Up, Down, Left, and Right] keys to move the cursor, you can use [Delete Character] or [Delete Entire Line] to process the file content, and you can also use [Copy and Paste] to process your file data.
2.2 Insert mode
Press and i,I,o,O,a,A,r,R
wait for any letter to enter the editing mode, generally speaking, i
just press.
2.3 Command line mode
Based on insert mode, enter Esc
, then enter :
to enter command line mode . In this mode, you can provide relevant instructions. The actions of completing reading, saving, replacing, leaving Vim, displaying line numbers, etc. are achieved in this mode.
Three, practical operation
(1) Establish a remote connection to operate the Linux system on Xshell. For details, please refer to Linux remote operation .
(2) Enter in Xshell vim hello.cpp
to enter the normal mode of Vim.
(3) Enter i
the insert mode and write the code.
(4) Enter Esc
, and then enter to :
enter the command line mode. Enter again wq
to complete saving the file.
4. Mode conversion and shortcut keys
4.1 Mode conversion
4.2 Shortcut keys
Normal mode :
- Copy the current line (yy), copy the 5 lines below the current line (5yy), and paste (enter p)
- Delete the current line (dd), delete 5 lines down from the current line (5dd)
- Use shortcuts to the last line (G) and first line (gg) of the document
- Undo an action in insert mode (u)
- Move the cursor to a line (line number shift+g)
Command line mode :
- Find a word in the file (/keyword, press Enter to search, enter n to find the next one)
- Set the line number of the file, cancel the line number of the file (:set nu and :set nonu)
Reference materials: 2021 Han Shunping learns Linux in a week