Linux starter Vim Quick use
Brief introduction:
Text editor, word processor, similar to nano word Fuquan editor, and SED for line editor
Source:
Vi:visual Interface
Vim:vi imprpbed (Enhanced version of VI)
Full screen editor, Mode editor
Vim mode:
1. Edit mode (Command mode)
2. Input mode
3, the last line mode
Mode conversion:
1. Edit--Output:
I: In front of the current Guan character, switch to input mode
A: After the current Guan character, switch to input mode
O: Under the current Guan character, 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 Guan is located, convert to input mode
O: Create a new line above the current cursor character and switch to input mode
2. Input---edit
Press ESC
3. Edit-and-last line
Enter in edit mode: symbol
4, last line--edit
Press the ESC one or more times, esc+ (for example, characters entered in the last line mode need to be pressed 2 times)
Note: The input to the last line mode cannot be converted directly, in the last line mode you can use the command to execute
After executing the command in the last line mode, go back to edit mode and enter! followed by the command you want to enter
! [Command]
such as:!ls-l
You can also append the command result to the current line
: r! [Command]
Example:: R!ls-r/etc/* Append the results of the file list output to the current file
First, open the file
Vim/path/to/somefile opening a single file
If the file exists as open, otherwise save as new when exiting
Vim/path/to/somefile
Vim +#: Open file, cursor to Custom line header
Vim +: Open the file, the cursor is positioned to the beginning of the last line
Vim +/pattern: Open a file to locate the beginning of the line that was first matched by PATTERN
For example: Vim +12/test/inittab Open the file and navigate to line 12th
Note: File Open is in edit mode by default
Second, close the file
1, the last line mode closed file
: Q exit
: Wq Save and exit
: q! Do not save exit
: W Save
: w! ---X Force save (for read-only files the administrator has permission)
2. Exit in edit mode
ZZ Save and exit
ZQ Do not save exit
3, the last line mode
:/w/path/to/file save to specified path
Third, mobile Guan (edit mode)
1, character-by-word movement:
H: Left
L: Right
J: Next
K: Up
#h: Move the # characters to the left (#表示移动指定数目的字符)
2, the word I unit to move
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
You can enter a specified number before executing a command to indicate that several commands need to be executed, such as:
#w #e #b
3w: Move backwards to the 3rd word head
3, line class Jump:
0: Absolute Character
^: first non-whitespace character at the beginning of a line
$: absolute end of line
H: The beginning of the first line of the current screen
L: The beginning of the last line of the current screen
4. Jump between rows
Edit mode
#G: Jump To Line #
G: Top row
GG: Same as 1G, equivalent to beginning of line
In the last line mode, enter the line number directly
Example: 10 (Jump to line 10th)
Four, turn the screen
CTRL+F: Flip one screen down
Ctrl+b: Turn up one screen before
Ctrl+d: Turn down half screen down
Ctrl+u: Turn up one screen up
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
Command mode:
d Command with jump symbol
#d跳转符: Delete cursor in the Jump range total #
#dw, #de, #db
DD: Delete the current cursor line s
#dd: Delete the # line containing the line in which the current cursor is located
In the last line mode:
Staradd,endaddd
#, #d: Delete from the first line to the first line
. D: Indicates when the forward
$d: Last line
+ #d: Down # line
Note: The deleted content is included in the buffer and can be revoked by
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 paste to the back of the character where the cursor is located if the copied or deleted content is not a whole line
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
y command with jump symbol
#y [Jump character]: the copy cursor is in the jump range of the total #
#dw, #de, #db
YY: Copy the current cursor in the row
#yy: Copy the # line that contains the line and down of the current cursor
Nine, modify: First delete the content, and then converted into the input mode
C: Same as D command
X. Replacement: R
R: Replace single character
R: Replace mode, which can be replaced by one line
Xi. undo Edit Operation U
Command mode
U: Undo the previous edit operation
The continuous u command can undo the previous N operations
#u: Directly undo the previous # edit operation
Undo the most recent revocation: ctrl+r
12. Repeat the previous edit operation
Press the command mode.
13. Visualization Mode
V: Select by character
V: Press Rectangular selection
14. Find
Command mode
/pattern
? PATTERN
N
N
PATTERN: Supports regular expressions
XV, find and replace
Using commands in last-line mode
Addr1,[email Protected]@[email protected]
1,$: First line to last row
%: Full text
Tip: Like the sed command, but you must specify the line number
16. Use Vim to edit multiple files
Vim FILE1 FILE2 FILE3 ...
In the last line mode:
File switching
: Next switches to the next file
:p Rev to switch to the first file
: Last switch to final file
: first to switch to file one
Exit
: QA All exits
: WQA Save All and exit
: Wq Save All
17. How to display a file in Split screen
Window split
In edit mode
Ctrl+w,s: Horizontal splitter window
Ctrl+w,v: Vertical Split Difference window
Switch between windows
Ctrl+w, ARROW (↑↓←→)
In the last line mode:
: QA Closes all windows
18. How to display multiple files in Split screen
Vim-o file1 file2 Horizontal split display
Vim-o file1 file2 Vertical split display
File switching
: First
: Wall
: Wqall
: Qall
Note: Split-screen display multiple files and individual files can be used together
19. Save some of the contents of the current file as a different file
: 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 executes the result and returns to the editor
: r! COMMAND appends the execution result content to the current line
22, environment settings (only the last line mode)
1. Display or suppress line numbers
: Set Number
: Set Nu
: Set Nonu
2. Set VIM to ignore or distinguish 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
5. View all environmental directives
: Set All
23. Configuration Files
/ETC/VIMRC Global
~/.VIMRC Local if not, you can manually create
For exercises and instructions:
Vimtutor Help Documentation
Vimtutor
Additional parts:
Editing a binary file
Open a file in binary mode
Vim–b Binaryfile
Extended command mode, using the XXD command to convert to a readable hexadecimal
:%!xxd
Editing a binary file
In extended command mode, use the XXD command to convert back to binary
:%!xxd–r
Save exit
This article is from the "Excalibur Trunks-kun" blog, please be sure to keep this source http://mengzhaofu.blog.51cto.com/10085198/1836523
Linux starter Vim Quick use