Vim is one of the most commonly used full-screen editors in Linux and operates in three modes
edit mode : Also called command mode, provides basic operations on text, such as moving up and down, and so on.
Input mode : As the name implies, input editing instructions
last-line mode : Built-in commands to run vim, such as search, storage, etc.
Conversion of several modes
Start vim default is edit mode
Edit mode--Input mode: I,i, A, A, O, O
Input mode--edit mode: Esc key
Edit mode--and last-line mode::
Last-line mode--edit mode: ESC
Two mode conversion requires first to edit mode, the last line mode and input mode can not be converted between
Vim exit:
Q! : Do not save exit
Wq or x: Save exit
wq!: Force Save exit
ZZ: Edit mode save exit, omit switch to last line mode
Basic command operations in edit mode
Move between characters: H down, j up, K left, L right
Jump between words: Where the cursor is, w the first letter of the next word, e current or the last letter of the next word, b the first letter of the previous word
Inline jump: ^ First non-whitespace letter at beginning of line, 0 absolute beginning, $ absolute line end
Move between rows: G last line, #G绝对的第几行
Edit operation
X: Delete cursor
#x: Delete the number of characters that the cursor contains
DW: Delete cursor to next prefix, including cursor
De: Delete the table marked out to the ending, including the cursor
DB: Remove cursor to its own prefix, not including cursor
d$ or DD: Delete entire row
#dd: Delete consecutive lines from the cursor
Note that the deleted results are saved in the buffer, so you can paste
P: Paste after cursor
P: Paste before the cursor
Of course you can copy
yy or y$: Copy entire line
Yw, ye, YB, #yy and D use the same
C: Modify is to delete and then convert directly to the input mode
and d usage can also be used, CC, #cc, CW, CE, CB, but the only difference is that the first word of CW is the default is to include the preceding spaces
Rx: Cursor out delete and replace with X
U: Undo Last Action
#u: Undo last few actions
Ctrl+r: Revert, undo undo action
G: Cursor moves to end of file
GG: Cursor moves to file header
Edit mode to input mode:
O: Insert next line and convert input mode
O: Insert the previous line and convert the input mode
A: After inserting to the cursor
A: After inserting into a line
I: Insert the money into the cursor
I: Inserting to the beginning of the line
Command for the last-line mode:
Search
:/: Back home plus match, search backwards
:? : Search Forward
N: Search results, forward lookup match
N: Find matches backwards
The last-line mode can also have an inline jump operation similar to 3yy
: #: Jump to the first few lines
: $: Jump to the last line
Start line, End line command: You can manipulate several lines at the same time, with command y, C, D. For example, 100,+2y copy 100 lines to 102 lines
File read and write related operations
Line write file:. The point represents the current row. For example, $w/tmp/test.txt writes all the contents of the current line to the last row/tmp/test.txt
Read the file to the specified location: for example, 7r/tmp/test.txt writes the file/tmp/test.txt content to line seventh below
Find patterns and replace content
Format: Custom look-up range s/Regular expression/content/parameter to replace
Parameters:
G: Full line substitution, default line replaces one
I: case-insensitive replacement
For example:
5,8s/\<test.*\>/excellent/gi globally replaces all words starting with test in rows 5 through 8 and is not case-sensitive
Some other common tricks under vim
Vim Visualization mode
V: After single character selection, you can perform d, Y, c operation
V: After row selection, you can perform d, Y, c operation
Turn screen
Ctrl+f: Turn Back a screen
Ctrl+b: Turn One screen forward
Ctrl+d: Half a screen backwards
Ctrl+u: half a screen ahead
Multi-file Mode
Multiple files can be opened with a command
Vim/var/log/messages1/var/log/messages2, this will open the Messages1 file and enter it in the last line mode: The next command opens the next file, and then the: Last command displays the previous file.
This mode can be used for copying between multiple files
Some commands that can be
: Next next file,:p revious previous file,: Last file, first file
: Wqall writes and launches all files
Multi-Window Mode
Multiple files
Command Vim/var/log/messages1/var/log/messages2 Parameters
-O: Horizontally separates two windows
-O: Vertically separates two windows
Ctrl+w, directional arrows, switching between different windows
Single File
After the file is opened with vim:
Ctrl+w, S: Horizontally delimited, a file
Ctrl+w, v separates a file vertically
Then switch between the different windows with ctrl+w, direction arrows
Inter-window Property configuration
: Set Nu,: Setnonu display or close line numbers
: Set AI,: Set NOAI on or off automatic line wrapping
: Set IC; : Set Noic Whether the query is case-sensitive
: Set Hlsearch,: Set Nohlsearch whether the search is highlighted
: Set Sm:set nosm whether to automatically match parentheses
: syntax On:syntaxoff syntax is highlighted
Note: If you change these parameters in the last-line mode, the exit is not valid, only temporarily. To modify the configuration file/ETC/VIMRC or ~/.VIMRC if you want to permanently work
VIM Command Summary