Vim Editor is a powerful text editor, divided into edit mode input mode in the last line mode, using Vim to edit a file
The default mode is edit mode;
Default mode: Command mode; edit mode
Input mode:
Last-line mode
Mode conversion
Edit mode---> Input mode
I key: Convert to input mode in front of the character where the cursor is located
A key: Converts to input mode after the character where the cursor is located
O Key: Create a new blank line below the cursor line to convert to input mode
I key: Convert to input mode at the beginning of the line where the cursor is located
A key: The line end of the line where the cursor is converted to input mode
O Key: Create a new blank line above the line of the cursor to convert to input mode
Input mode-----> Edit mode
ESC key to
Edit mode-----> last-line mode
: Key to
Last-line mode----> Edit mode
Two consecutive ESC keys
Vim-o (horizontal split) filename filename opens multiple files at the same time
-O Vertical Split
CTRL+W switching
Edit mode
Cursor Jump
H: Move left
L: Move Right
J: Move Down
K: Move Up
#h: Move to the left # times
Inline jump
GG jumps to the first line
G jump to the last line
NG jumps down n rows, counting from the line where the cursor is located
Delete command
D: Delete
DD: Delete cursor in the row
DGG: Delete all rows that are on the line where the cursor is located
DG: All the rows down
NDD: Deletes n rows from the cursor line, containing the cursor in the row
CC: Delete the line of the cursor and convert directly to input mode
C: Delete The content behind the cursor and convert to input mode
In-line jump
^: Beginning of the line
$: End of line
Revoke
U: Undo
Copy
YY: The copy cursor is in the row
y^: From where the cursor is, copy to the first row
y$: Copy to Last row
Paste
P: Paste below the line where the cursor is located
Page
Ctrl+f down one page
Ctrl+b up one page
Visual Block mode
V: Select the character that the cursor crosses
V: Select the line across the cursor
Same document, split screen display
CTRL+W--->s key split horizontally
Ctrl+w----V-Key Vertical split
Two times ctrl+w split screen jump
Ctrl+w---> Arrows: Split-screen jump
Close File
Last-line mode
Wq Save exit
! Force exit
End-line mode address delimitation
1,7d Delete 1 to 7 rows
% Full text
1,$ first line to best line
Search
/keywords look up from the cursor to the tail
The keyword looks from the cursor to the header
N: Next
N: Previous
Keywords can use patterns
Pattern: A matching criterion consisting of regular expressions
Such as
Match use and number 1 contain any characters that appear any time
/use.*1
Window Property Definition
Last-line mode
Set NU Display line number
Set AI automatically indents the next line to automatically match the previous line indent
Set IC ignores character case
The find substitution delimiter can be replaced with the @ \ Translator:
Cases:
Replace the/tmp/test with the/test/tmp
:%s/\/tmp\/test/\/test\/tmp/g
:%[email protected]/tmp/[email Protected]/test/[email protected]
: Address delimitation s/Find mode/Replace with content/gi find mode supports regular expressions
Default matches to the same row, replacing only the first group
G: Global Substitution
I: Case insensitive
&: can refer to the entire string previously found
Example
1. Remove the # Number of the comment line starting with #
%s/^#//
2. Match to Dev, or dev, add on ice after, match character format unchanged
%s/[dd][ee][vv]/&ice/g
3. Add the # Number to the beginning of the whitespace character
%[email protected]^[[:space:]]@#&@
4. Add a # to a line beginning with a character
1s/^!/#&/
5. For a custom range of lines, add # at the beginning of the line
1,25s/^/#/g
Vim configuration file
Global:/ETC/VIMRC
Personal: ~/.VIMRC does not exist by default
This article is from the "Hanging Sword" blog, please be sure to keep this source http://sublime.blog.51cto.com/8856101/1445083
Linux Basics-----Vim