Vim’s three modes
-
Basic mode (command mode) : Press Esc to activate —- to perform operations such as delete, undo, and locate
-
Last line mode: In basic mode, enter: to activate —- to perform operations such as searching and saving
-
Insert mode: In basic mode, enter I to activate (A, CW, C $, s can also)—- To insert text
-
Cursor movement:
In basic mode, H, J, K and L correspond to the left, top and right of the small keyboard
-
Move operation:
0: move to the first line $: Move to the end gg: move to the first line G: move to the last line nG: Move to the NTH line CTRL + G: View the current line nw: move forward n words and stop at the beginning ne: Move forward N words and stop at the end CTRL +O: CTRL +I: Moves the cursor forward once
-
Delete operation:
DNW: delete n words. De: delete from the cursor to the end of the word. D $: delete from the cursor to the end of the line
-
Insert operation:
O: Insert A blank line below the current line and enter the insert mode. O: Insert A line above the current line and enter the insert mode. A: Insert at the end of the line where the current cursor is located
-
Modify operation:
R: replace the character where the cursor is located R: replace the character where the cursor is located cw: modify the word to the end of the word C $: modify the content to the end of the line NDD + p: Cut and paste the line :s/old/new: replace the first old in the line with new: s/old/new/g: %s/old/new/g: change all the old values of the text to new :%s/old/new/gc: change all the old values of the text to new and ask for instructions one by one
-
Undo/Restore operations:
U: undo a step operation U: undo the operation in the line CTRL + R: restore (undo the undo operation)
-
Query operation:
%: stops on the brackets available, matches the brackets to locate/look up words: displays all the words to look up, starting with the first target word? N: / n: / n: / n: / n: / n: / n: / n: / n: / n: / n: / To restore the case-sensitive query mode :set HLS IS: query highlights :nohlsearch: Unhighlights
-
Temporary use of shell commands in Vim (with the help of last-line mode)
:! Ls: temporarily view the files in the current vim running directory :w BACKUP: BACKUP the current file contents in BACKUP: r OTHERS: insert the contents in file OTHERS into the line where the cursor stops :help w: view the help documents in split screens, :q! You can exit the help document
-
The use of visual function V
V + H J K L Selected area + y + P: Copy and paste V + H J K L Selected area + D + P: Cut and paste V + H J K L Selected area + :w BACKUP: Saves the selected text in the BACKUP file
-
Create the startup script vimrc
-
Start editing the vimrc file, depending on your operating system:
:edit ~/.vimrc This is the command used by Unix systems :edit $VIM/_vimrc This is the command used by MS-Windows systemsCopy the code
-
Then read the contents of the vimrc sample file:
:r $VIMRUNTIME/vimrc_example.vim
Copy the code
-
To save the file, run the following command:
:write The next time you start Vim, the editor will have syntax highlighting. You can add as many Settings as you like to this vimrc file. For more information please enter :help vimrc-introCopy the code
- Enter :help or press a key or key to open the help window.
- Enter :help CMD to find help with CMD commands.
- Enter Ctrl-W to jump between Windows.
- Type :q to close the help window
- You can create a vIMRC startup script file to save your preferred Settings.
- When you enter the: command, you can press Ctrl-d to view possible completion results. Press to use a completion. 234