-
Introduction
-
vim Command
(1) Cursor Movement: Key: shift+6 or ^ Action: Move the cursor to the first line Key: shift+4 or $ Action: Move the cursor to the end of the line Key: gg Action: Move the cursor to the first line Key: G or shift+g Action: Move the cursor to the last line Key: ctrl+b or PgUp Action: Scroll up Key: ctrl+f or PgDn Action: Scroll down(2) Copy Operation: Key: yy Action: Copy the current line where the cursor is, press p to paste it where you want Key: number yy Action: Copy a specified number of lines down from the current line (including the current line) Key: ctrl+v, press ↑↓←→ arrow keys to select the area to copy, press yy to copy, press p to paste(3) Cut/Delete Operation: Key: dd Action: Cut/Delete the current line where the cursor is, the next line moves up Note that dd is technically a cut command, but if you cut without pasting, it effectively deletes Key: number dd Action: Cut/Delete the current line where the cursor is, cut/delete a specified number of lines down, the next line also moves up Key: D Action: Cut/Delete the current line where the cursor is, the next line does not move up, the current line becomes a blank line(4) Undo/Redo Operation: Undo: Type :u or u 【undo】 Redo: ctrl+r to restore (cancel) the previous undo operation
Entering Method: Press i/a/o/I/A/O/S in command mode Common: i(insert), a(after) Exit Method: Press the esc key
Entering Last Line Mode: After entering the file, press : to enter Save Operation Type: ":w" to save the file Type: ":w path" to save as Exit Type ":q" to exit the file Force Exit Type ":q!" to force exit without saving changes Search/Find Type: "/keyword" To switch to the next result in the search results: N/n To cancel highlighting, type: ":nohl" Replace :s/search keyword/new content Replace the first occurrence of the condition in the current line :s/search keyword/new content/g Replace all occurrences of the condition in the current line :%s/search keyword/new content Replace the first occurrence of the condition in each line of the entire document :%s/search keyword/new content/g Replace all occurrences of the condition in the entire document % means the entire file g means global Show Line Numbers Type: "set nu" To cancel, type: "set nonu"
-
Four Ways to Open a File with vim
vim file path
Action: Open the specified file
vim +number file path
Action: Open the specified file and move the cursor to the specified line
vim +/keyword file path
Action: Open the specified file and highlight the keyword
vim file path1 file path2
Action: Open multiple files simultaneously
-
Configure vim
1. Configuration entered in last line mode when the file is opened (temporary)
2. Personal configuration file (~/.vimrc, create if it does not exist)
3. Global configuration file (provided by vim, /etc/vimrc)
Personal Configuration File
① After creating the personal configuration file, enter editing mode
② Configure in the configuration file: for example, to show line numbers: set nu
After configuration, vim will always display line numbers when opening files
Note: If the same configuration item exists in the personal configuration file, it takes precedence; if it does not exist, the global configuration file is used.
Thank you for reading my article, I am IT Observer. If you like it, please give a free follow!