Vim/vi Mode of work
First, insert text
| Command |
Describe |
| I |
Inserts text match either the current character |
| I |
Inserts text at the beginning of a line |
| A |
Add text after the current character
|
A
|
Add text at the end of a row
|
O
|
Inserts a blank line after the current line
|
O
|
Inserts a blank line before the current line
|
R
|
Enter text in a overtype format
|
$
|
Move to end of line
|
0
|
Move to the beginning of a line |
| Command |
Role |
| H |
Move to upper Screen |
| M |
Move to the center of the screen |
| L |
Move to the bottom of the screen |
Second, the positioning command
| Command |
Role |
| : Set Nu |
Set line number |
| : Set Nonu |
Cancel line number |
Gg G |
To the first line To the last line |
| NG |
to Nth Line |
| : N |
to Nth Line |
Third, delete the command
| Command |
Role |
| X |
Delete the character at the cursor |
| Nx |
Delete the following n characters at the cursor location |
| Dd |
Delete the row of the cursor, NDD delete the following n rows |
| Dg |
Deletes the contents of the line to the end of the file at the cursor |
| D |
Delete from the cursor to the end of the line |
| : n1,n2d |
Delete a row of the specified range |
Iv. copy and Cut commands
| Command |
Role |
| YY, Y |
Copy as Forward |
| Nyy, NY |
Copy Current line n line |
| Dd |
Cut forward |
| Ndd |
Cut Current line N line |
| P, p |
Paste on the line or line where the current cursor is located |
V. Replacement and cancellation
| Command |
Role |
| R |
Replace the character where the cursor is located |
| R |
Replaces the character at the cursor, ESC ends |
| U |
Cancel the previous action |
Vi. Search and Replace functions
| Command |
Role |
| /string |
Searches forward for the specified string |
| N |
Searches for the next occurrence of the specified string |
| :%s/old/new/g |
Authoritative replace the specified string |
| : n1,n2s/old/new/g |
Replaces the specified string within a certain range |
1. Search
Ignore case
: Set IC
/string
Cancel case ignores:
: Set Noic
2. Replace
Old: Replaced characters
NEW: Characters to replace
Vii. Save exit: Shift+zz
Save only, do not exit: W/home/back.bak
For files that have read-only permissions, only administrators and the owner of the file can pass: wq! Forced to change and save, other users cannot change.
Viii. Common usage
1. Import other files
: R [FileName] 2. Execute commands in VI and display without exiting:! [Command] Note: The combination of 1 and 2 uses: Import the execution result of the command into the VI example: Import the current time into VI: R!date 3. Define shortcut keys: Map Shortcut Trigger Command example:: Map ^p i#<esc> (^ = Ctrl+v+p Implementation method) (I Navigate to the beginning of the line) implementation (CTRL + P): Navigate to the beginning, insert #, exit: Map ^b 0x to the beginning of the line, and delete First character 4. Continuous line Comment:: n1,n2s/^/#/g sharp Corner Number (^): Indicates beginning of row of lines uncomment:: N1,n2s/^#//g the beginning of the line with empty instead if the comment is two slashes (C language):: n1,n2s/^/\/\//g anti- Slash (\): Escape character 5. Replace (a large number of shortcuts can not remember): AB mymail jk20101002@126.com Cancellation definition: Unab mymail above the shortcut keys in the Exit VI after the disappearance, want to let them save, then change its VI configuration profile (~ /.VIMRC) Example: Vim ~/VIMRC set nu map ^p i#<esc> ab mymail 2010@126.com