Vi:visual Interface
Vim:vi improved
Full screen editor, modal editor
Vim mode:
Edit mode (Command mode)
Input mode
Last-line mode
Mode conversion:
Edit--Input:
I: In front of the character of the current cursor, switch to input mode;
A: After the character of the current cursor, switch to input mode;
O: At the bottom of the current cursor line, create a new row and switch to input mode;
I:在当前光标所在行的行首,转换为输入模式A:在当前光标所在行的行尾,转换为输入模式O:在当前光标所在行的上方,新建一行,并转为输入模式;
Input-to-edit:
Esc
Edit-to-last line:
:
Last line--edit:
ESC, ESC
First, open the file
# vim /path/to/somefile
Vim +#: Open the file and locate it on line #
Vim +: Open the file and navigate to the last line
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN
Default in edit mode
Second, close the file
1, the last line mode closed file
: Q exit
: Wq Save and exit
: q! Do not save and exit
: W Save
: w! Forcibly saved
: Wq---: X
2. Exit in edit mode
ZZ: Save and exit
Third, move the cursor (edit mode)
1, character-by-word movement:
H: Left
L: Right
J: Next
K: Up
#h: Move # characters;
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
3, in-line jump:
0: The absolute beginning
^: first non-whitespace character at the beginning of a line
$: absolute end of line
4. Jump between rows
#G: Jump to Line #;
G: Last line
末行模式下,直接给出行号即可
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 a single character at the cursor location
#x: Remove the total # characters from the cursor and backwards
Vi. Delete command: D
The D command is used in combination with the jump command;
#dw, #de, #db
DD: Deletes the current cursor in the row
#dd: Delete the line containing the line of the current cursor;
In the last line mode:
Startadd,endaddd
.: Indicates when the forward
$: Last line
+#: Down # line
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 if the copied or deleted content is a non-full row, paste it in front of the character in the cursor;
Eight, copy command y
Usage with d command
Nine, modify: First delete the content, and then converted into the input mode
C: Usage with d command
X. Replacement: R
R: Replacement mode
Xi. undo Edit Operation U
U: Undo the previous edit operation
The continuous u command undoes the previous n edit operations
#u: Undo Recent # edits directly
Undo the most recent undo action: Ctrl+r
12. Repeat the previous edit operation
.
13. Visualization Mode
V: Select by character
V: Select by rectangle
14. Find
/pattern
? PATTERN
N
N
XV, find and replace br/> using the S command in the last-line mode
ADDR1,[email protected]@[email protected]
%: Full text
16. Use Vim to edit multiple files
Vim FILE1 FILE2 FILE3
: Next switches to the next file
:p Rev Switch to the previous file
: Last switch to final file
: first to switch to file one
Exit
: QA All exits
17, split screen display a file
Ctrl+w, S: Horizontal splitter window
Ctrl+w, V: Vertical splitter window
Toggle the cursor between windows:
Ctrl+w, ARROW
: QA Closes all windows
18. Edit multiple files in a window
Vim-o: Horizontal Split display
Vim-o: Vertical Split display
19. Save some of the contents of the current file as a different file
Use the W command in the last row mode
: W
: Addr1,addr2w/path/to/somewhere
20. Populate the contents of another file in the current file
: R/path/to/somefile
21. Interacting with the shell
:! COMMAND
22. Advanced Topics
1. Display or suppress line numbers
: Set Number
: Set Nu
: Set Nonu
2. Display ignores or distinguishes character case
: Set ignorecase
: Set IC
: Set Noic
3. Set Auto Indent
: Set Autoindent
: Set AI
: Set Noai
4. Check the found text highlighting or canceling
: Set Hlsearch
: Set Nohlsearch
5. Syntax highlighting
: Syntax on
: Syntax off
23. Configuration Files
/etc/vimrc
~/.vimrc
Vim Command Detailed