Vi:visual Interface
Text editor, word processor
Ascii
Vim:vi imporved
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 that the current cursor is in, switch to input mode:
A: After the current cursor character, switch to input mode:
O: Under the current cursor line, create a new row and switch to input mode:
I: Converted to input mode at the beginning of the line at which the cursor is currently located
A: At the end of the line where the current cursor is located, convert to input mode
O: At the top of the current cursor line, create a new row and switch to input mode:
Input-to-edit:
Esc
Edit-to-last line
:
Last line--edit
Esc
#vim/path/to/somefile
First, open the file
Vim +#/file Open file, position the cursor on line #
Vim + filename Opens the file and the cursor 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
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 Force save, only Root has permission
: 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
#w: Jumps to multiple words ...
3, in-line jump:
0: The absolute beginning
^: first non-whitespace character at the beginning of a line
$: absolute end of line
4, between the lines jump:
#G: Jump To Line #:
G: Last line
In the last line mode, directly to the travel number can be
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 conjunction with the jump command
#d跳转符: Remove the # characters after a jump break
#dw, #de, #db
DD: Deletes the current cursor in the row
#dd: Delete the # line including the line where the current cursor is located
In the last line mode:
Startadd,endaddd
eg:1,8d Delete 1-8 rows
. Indicates when to move forward
$ last line
+# Down # line
Eg:1,$-3d Delete the first line to the penultimate line
Seven, Paste command p
P: If you delete or copy to an entire row, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it after the character that contains 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 that contains the cursor if the copied or deleted content is not a whole line:
Eight, copy command y
Usage with d command
YY Copy a row
Nine, modify: Delete the content first, in the conversion to input mode
C: Usage with d command
eg:cc,c$ ...
X. Replacement: R
Replace a single character with a common term
Eg:rx, replacing the current character with an X
R: Replacement mode
Xi. Undo Edit Operations
U: Undo the previous edit operation
Continuous u command to undo previous N Operations (up to 50 undo)
#u: Undo the edit operation of the last # times directly
Undo most recent revocation (Restore last revocation): Ctrl+r
12. Repeat the previous edit operation
.
13. Visualization Mode
V Select by character
V Select by Rectangle
14. Find
/pattern looking down
? PATTERN Up Lookup
N Next Match result
N Previous Match result
XV, find and replace
Use the S command in the last-line mode
Addr1,[email Protected]@[email protected]
G Global Substitution
I ignore case
1,$
%: Full text
Exercise: Replace Ftp://instructor.example.com/pub in the/etc/yum.repos.d/server.repo file with Http://172.16.0.1/yum
%s/ftp:\/\/instructor\.example\.com\/pub/http:\/\/172.16.0.1\/ymm/gi
%[email protected]://instructor\.example\.com/[email Protected]://172.16.0.1/[email protected]
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
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 another 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/somewhere
21. Interacting with the shell
:! COMMAND
22. Advanced Topics
1, display or cancel line number:
: Set Nu (number)
: Set Nonu
2. Display ignores or distinguishes character case
: Set IC (ingorecase)
: Set Noic
3. Set Auto Indent
Set AI (autoindent)
Set Noai
4. Check the found text highlighting or canceling
: Set Hlsearch
: Set No Hlsearch
5. Syntax highlighting
: Syntax on
: Syntax off
23. Configuration Files
/etc/vimrc
~/.vimrc
Vim Editor Feature notes