Vim Editor Detailed
Vim for File Editor: Word processor
Vi:visual Interface
Vim:vi improved VI's enhanced version
There are three modes of vim:
Edit mode (Command mode)
Input mode
Last-line mode
Mode conversion:
Edit mode--Input mode:
I: Switch to input mode before the current cursor character
A: After the current cursor character, switch to input mode
o: Insert a row below the current cursor character, and convert to input mode
I: Converted to input mode at the beginning of the current row
A: At the end of the line at the current line, convert to input mode
O: Insert a row above the current cursor character, and convert to input mode
Input mode--edit mode Press ESC
Edit mode--mo-line mode press:
Last line mode--edit mode press Esc,esc two times
Usage: #vim FILENAME
First, open the file
Vim +n: Represents an open file and is positioned on the nth (NUM) line
Vim +: Indicates open file and navigates to the last line
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN
When you open a file, it is in edit mode by default.
Second, close the file
1. Closing the file in the last line mode
: Q exits the file directly
: Wq=x Save and exit
: q! Save and exit
: W Save
W: Forcibly saved
2. Exit in edit mode
ZZ: Save and exit
Third, move the cursor (in edit mode)
1. Character-by-word movement:
H: Move left
L: Move Right
J: Move Down
K: Move Up
N (H, L, J, K) moves n characters at a time
2. Move in Word units
W: Move to the beginning of the next word
E: Jumps to the ending of the current or next word
B: Jump to the beginning of the current or previous word
N (w, E, b) beats n words at a time
3. In-line jump:
0: Absolute beginning of line (including whitespace characters)
^: first non-whitespace character at the beginning of a line
$: absolute end of line
4. Jump between rows
N (G): jumps to Nth line;
G: Jump to the last line
In MO-line mode, Direct: n jumps to nth row.
Four, turn the screen
CTRL+F: Flip one screen down
Ctrl+b: Turn up one screen
Ctrl+d: Flip Down half screen
Ctrl+u: Flip up half screen
V. Delete a single character
X: Delete the character of the cursor, one character at a time
N (x): Delete all n characters from the cursor and backwards
Vi. Delete command D
DD: Delete cursor in the row
N (DD) Delete the row of the cursor and a total of n rows down
d$: Delete cursor position to end of line
D0: Delete cursor position to beginning of line
N (DW, DE, db): delete n words
In the last line mode:
Start line, end row D Example: 1,8d Delete first to eighth row
.: Indicates when the forward
$: Last line $-3 indicates the third line to the bottom
+n: Down N-line example: 1,+5 delete the row of the cursor and the next 5 rows
Seven, Paste command p
P: If you delete or copy to a whole line, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full line, paste it behind the character of the cursor;
P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and paste to the front of the character where the cursor is located if the copied or deleted content is not a whole line
Eight, copy command y
YY: The line where the cursor is copied
N (yy) copy cursor row and down total n rows
y$: Copy cursor position to end of line
Y0: Copy cursor position to beginning of line
N (yw, ye, YB): copy n words
Nine, modify, first delete the specified content, and then converted to input mode
CC: Delete the line where the cursor is located and convert to input mode
N (cc) Delete the row of the cursor and a total of n rows down and convert to input mode
C $: Delete cursor to end of line and convert to input mode
C0: Delete the cursor position to the beginning of the line and convert to input mode
N (CW, CE, CB): delete n words and convert to input mode
X. Replace command R
R: Example of the character of the replacement cursor: R--A press R at the cursor position to replace the character of the cursor with a
R: Enter replacement mode
Xi. undo Edit Operation U
U: Undo the previous edit operation
The continuous u command can undo the previous N operations. (Up to 50 times)
N (U): Undo the last N edit operation directly
Restore the most recent undo operation: Ctrl+r
12. Repeat the previous edit operation
.: Repeat the previous edit operation
13. Visualization Mode
V: Select by character
V: Select the use of rectangular block: Edit mode Press V, then left and right arrows to select content, you can directly copy, delete and other operations.
14. Find
/pattern from file header to tail
? PATTERN looks from the line where the cursor is located to the file header
N: when matching to multiple, n looks down to the next
N: When matching to multiple, N finds the next
XV, find replacement (used in the last line mode)
Startline,endlines/pattern/string/gi
., $-1s/ba/ob/gi from the current line to the penultimate row to find all the BA replaced by OB ignores case global substitution.
See a few days of the tutorial, think first to learn an editor or is very necessary, so first to organize an editor of the use of the method to everyone, according to the tutorial purely hand-organized content, there are errors in the place also hope that everyone guidance, hope to everyone helpful.
This article is from the "REDHAT" blog, make sure to keep this source http://xuezhe6.blog.51cto.com/4415365/1967638
The Vim editor explains in detail