Vim is a powerful text editor, by default there are three modes: Command mode, insert mode, edit mode, use # Vim file to open a file, the default into the command mode, different modes of direct switching as follows
A. Command mode switch to insert mode: ESC key returns command mode
I: Start inserting at the cursor
I: Inserts at the beginning of the cursor
A: Start inserting at the end of the line (append)
o: Insert a new line under the cursor
B. Command mode toggle edit mode: Direct input: Can, enter the command mode return
Common commands:
1.1 positioning command (in command mode)
1.1.1 Cursor moves to the beginning of the line: 0
1.1.2 Cursor move to end of line: $
The 1.1.3 cursor moves to the first character of the file first: GG
The 1.1.4 cursor moves to the end of the file, the first character: G
1.2 copy && cut (delete) && paste (in command mode)
1.2.1 Copy line: yy
1.2.2 Copy n rows: Nyy
1.2.3 Cut one line: DD
1.2.4 Cut n rows: ndd
1.2.5 cut to end of line: D
1.2.6 cut to end of file: DG
1.2.7 cut the specified line:: n1,n2d edit mode N1: Start line number, N2 stop line number, note that this command is in command mode, and note that D, do not forget to write
1.2.8 paste under cursor: P
Note: Delete and cut commands are the same in vim, as long as they are not pasted, cut is deleted
1.3 Replacement && Search (Command mode)
1.3.1 replaces a single character at the cursor: R, and then enter the character you want to replace
1.3.2 into replacement mode: R, can be replaced continuously, ESC exits to command mode
1.3.4 Bulk Replacement: Replace the OLDSTR string with Newstr, edit mode
1.:%s/oldstr/newstr/c full text replacement, there are inquiries prompted
2.:%s/oldstr/newstr/g full text replacement, no inquiry tips
3.: n1,n2s/oldstr/newstr/c N1 line to N2 between the line to replace, there are inquiries prompted
4.: n1,n2s/oldstr/newstr/g N1 line to N2 line replacement, no query prompts
1.3.5 Search: Enter vim Shime do not ignore case-insensitive search
1. General Search:/str
2. Fuzzy search: First set the file to ignore case, in edit mode input: Set IC
Settings file does not ignore case: set Noic
After you find it, press N to find the next
1.4 Save Exit: (in edit mode)
1.4.1 Save: W
1.4.2 Save as: w NewFileName
1.4.3 Save and exit: Wq
1.4.4 do not save exit: Q.
1.4.5 forced Save: Wq. Refers to a read-only file, but only the owner of the file and the root user can use this command
1.4.6 undo Operation: U Command mode (undo)