use of vim

vim is an upgraded version of vi; vim can display the color of the text
Install the vim package vim-enhanced
If you do not know the installation package, you can use the command below to check which package the vim command is installed by.

[root@yong-02 tmp]# yum provides "/*/vim"
[root@yong-02 tmp]# yum install -y vim-enhanced

Vim editing files will display colors, which is related to the specific content of the files. Files in the /etc/ directory will display colors, but the same files may not display colors in other directories. There are many conditions for vim to display colors, so Don't get too hung up on this.

vim has three modes: general mode, editing mode, command mode

The cursor moves quickly in normal mode

  • j cursor moves down
  • kCursor up
  • h cursor to the left
  • l, space, cursor right
  • gg cursor quickly locates the first character of the first line
  • G locates the last character at the end; 5G quickly locates 5 lines
  • shift+4 go to the end of the line
  • shift+6 locates the first character at the beginning of the line
  • 0 Press 0 to locate to the beginning of the line (the difference is that 0 is to return to the beginning of the line, and shift+6 is to return to the first character at the beginning of the line)
  • ctrl+b page up
  • ctrl+f page down

Cut and paste in normal mode

  • x deletes the characters after the cut cursor; 3x deletes 3 characters after the cut cursor
  • X deletes the character before the cut cursor
  • dd deletes and cuts the entire line; 3dd deletes 3 lines under the cut cursor
  • yy copies the cursor line; 3yy copies the 3 lines under the cursor
  • p paste to the line below the cursor
  • P paste to the line above the cursor
  • u is the rollback, which can only be rolled back 50 times, the system stipulates
  • ctrl+r go back
  • v Visualize, then jkhl to select the area content; then press x to delete the area you selected

edit mode

  • i insert at the cursor
  • shfit+i(I) insert at the beginning of the line
  • a insert after the cursor
  • shift+a(A) inserts at the end of the line
  • oInsert a line below the cursor line
  • shift+o(O) insert above the cursor line
  • esc to exit edit mode

command mode

  • :q quit
  • :wq save and exit
  • :q! Force quit
  • :wq! Force save and exit
  • :set nu display line number
  • :set nonu cancel line numbering
  • :nohl to de-highlight
  • /iptables find content; press n to find down, press N to find up
  • ?iptables also means search
  • s replace
  • :1,20s/IPTABLES/iptables/g
  • s replace; g global, only one of each line is replaced without g.

practise

  1. Move down, right, left, right 6 characters respectively; 6j 6l 6h 6l

  2. Down and up two pages respectively; Ctrl+f and Ctrl+b

  3. Move cursor to line 49; 49G

  4. Move the cursor to the end of the line, and then to the beginning of the line; Shift+4 , Shift+6

  5. Move to the last line of the 1.txt file; G

  6. move to the first line of the file; gg

  7. Search the file for occurrences of the dnsmasq string and count the number of occurrences of the string; enter /dnsmasq and press n

  8. Replace dnsmasq from the first line to the tenth line with dns;
    1,10s/dnsmasq/dns/g

  9. Restore the previous operation; u

  10. Replace all etc in the whole file with cte; 1, $s/etc/cte/g

  11. Move the cursor to line 25, delete the string ly; enter 25G and press Enter, then press j to move the cursor to the right to find ly, press v to select, then press x

  12. Restore the previous operation; u

  13. delete line 50; 50G dd

  14. Restore the previous operation; u

  15. Delete everything from lines 37 to 42; 37G dd

  16. Restore the previous operation; u

  17. Copy the contents of line 48 and paste it below line 52; 48G yy 52G p

  18. Restore the previous operation; u

  19. Copy line 37 to 42 and paste it above line 44; 37G 6yy 44G p

  20. Restore the previous operation; u

  21. Move lines 37 to 42 below line 19; 37G 6dd 19G p

  22. Restore the previous operation; u

  23. Move the cursor to the first line, and change the content of the first line to #!/bin/bash; first press gg to position the cursor to the first line, then press the letter A to enter the editing mode, and move the cursor to the end of the line at the same time. After modification, the Esc key exits the editing mode.

  24. Insert a new line below the first line and enter #Hello! ; Press o to enter edit mode, move the cursor down to a new line, and type #Hello !

  25. Save the document and exit;
    press Esc to exit edit mode, press Shift+, enter wq, and press Enter.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324446559&siteId=291194637