Three
VI and VIM The biggest difference is to edit a text VI does not display color, vim display color.
- Installation: Yum install-y vim-enhance
There are three modes of VIM
A: General mode
- Up or down cursor KJHL
- ctrl+b Text to page forward,ctrl+f text to page backward
- 0 or Shift+6 move the cursor to the line of the bank,shift+4 move the cursor to the beginning of the bank
- GG moves to the beginning of the line,G moves to the end
- NG moves to ground n rows
- x and x remove one character forward or backward
- NX removes n characters backwards
- DD Delete or cut the line where the cursor is located
- ndd Delete or cut n rows where the cursor is located
- yy The copy cursor is in the row
- nyy copy n rows from the line where the cursor is located
- p or P pastes the copied or pasted content from the beginning of the cursor
- u Restore previous action
- v to move the cursor after V or select the specified character, you can copy, paste and other operations
B: Edit mode
- i insert in the current word match either
- I Insert at the beginning of the line where the cursor is located
- a in the current word specifier insert
- A in the row position of the line where the cursor is inserted
- o Insert a new row on the next line of the current row
- O Insert a new row on the previous line in the current row
Press "ESC" key to enable VIM to enter command mode from edit mode
C: Command mode
Enter in general mode : or/ enter command mode
- /word After the cursor looks for a string word, press N to go back to search
- ? Word looks for a string before the cursor word. Press N to go forward to search
- : n1,n2/word1/word2/g finds word1 between N1 and N2 rows and replaces Word2, without G replacing the first word1 of each row
- : 1, $s/word1/word2/g replace all word1 in the document with Word2. Replace the first word1 of each row without G
- : w Save text
- : Q quit vim
- : WL forcibly saved, under root user, even if the file is read-only can be saved
- : q! force quit, do not save
- : Wq Save and exit
- : Set nu Displays line number
- : Set Nonu does not display line numbers
Practice makes perfect, make unremitting efforts ....
Linux Learning (3)--vim text editing tools