1. Three modes
- normal mode
- Opening a file with vim will directly enter 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 characters] or [Delete entire lines]** to process the file content, or you can use [ Copy, Paste ] to process your file data.
- Insert mode
- Only after pressing any letter such as i, l, o, O, a, A, R, etc. will you enter the editing mode. Generally speaking, just press i.
- command line mode
- In this mode, you can be provided with relevant instructions. Actions such as reading, saving, replacing, leaving vim, displaying line numbers, etc. are all accomplished in this mode!
2. Case
Use vim to develop a Hello.java program, save, step instructions and demonstration
Used here in xshell.
-
Indicates using vim to write the Hello.java program
-
Enter i to enter insert mode
-
Write a program; enter esc to exit mode; then enter: command mode; enter wq to write and exit.
3. Switching between vi and vim modes
4. vi and vim shortcut keys
-
Copy the current line yy, copy the 5 lines 5yy downward from the current line, and paste (enter p)
-
Delete the current row dd, delete 5 rows 5dd from the current row downwards
-
Search for a certain word in the file [under the command line/keyword, press Enter to search, enter n to find the next one]
-
Set the line number of the file and cancel the line number of the file. [At the command line: set nu and :set nonu]
-
Edit the /etc/profile file and use shortcut keys to go to the last line [G] and the first line [gg] of the document
-
Enter "hello" in a file and then undo this action u
-
Edit the /etc/profile file. In normal mode, enter 20, then enter shift+g to locate line 20.
-
See more organized documents