Linux - Quick Start with vim and vi

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.

  1. Indicates using vim to write the Hello.java program
    Insert image description here
    Insert image description here

  2. Enter i to enter insert mode
    Insert image description here

  3. Write a program; enter esc to exit mode; then enter: command mode; enter wq to write and exit.
    Insert image description here
    Insert image description here

3. Switching between vi and vim modes

Insert image description here

4. vi and vim shortcut keys

  1. Copy the current line yy, copy the 5 lines 5yy downward from the current line, and paste (enter p)

  2. Delete the current row dd, delete 5 rows 5dd from the current row downwards

  3. Search for a certain word in the file [under the command line/keyword, press Enter to search, enter n to find the next one]

  4. Set the line number of the file and cancel the line number of the file. [At the command line: set nu and :set nonu]

  5. Edit the /etc/profile file and use shortcut keys to go to the last line [G] and the first line [gg] of the document

  6. Enter "hello" in a file and then undo this action u

  7. Edit the /etc/profile file. In normal mode, enter 20, then enter shift+g to locate line 20.

  8. See more organized documents

Guess you like

Origin blog.csdn.net/isak233/article/details/132841100