VI and VIM's madness

Source: Internet
Author: User

1. The relationship between VI and VIM:
Vim can be understood as the upgrade version of VI, support shell script programming;
VI existence reason: All Unix like systems are built into the VI editor, while the individual tools will actively call VI, such as crontab.

2. About the three modes of VI:
General mode
Edit mode
Command mode

3. General mode command for VI:
1) Cursor Movement:
Single characters: H (left), L (right), K (UP), j (bottom);
Costume: ^/0/home, line tail: $/end;
Multiple lines: NK, NJ. If you move up 10 lines: 10k;
Paging: Up one page, CTRL + B; Page DOWN, ctrl + F; Up half page, CTRL + U; down half page, ctrl + D;
Any line: NG;
File header: gg/1g, File not: G;
Screen head: H, end of screen: L, Middle: M

2) Find replacement:
Look up:? word
Look down:/word
Previous: N, Next: N (note: When looking up, n with N action Twist)
Replace:: N1,n2s/word1/word2/g[c], where N1 is the start line, N2 is the end line, and C is required to be confirmed before replacement. If the word1 string is searched from the first line to the last line, and the string canceled to Word2, and the prompt character is displayed to the user before the substitution, the command is: 1, $s/word1/word2/gc.

3) Delete:
Delete character:
Move forward, X. Delete Multiple at a time, NX
Backwards, x. Delete multiple, NX at a time
Outfit to current position, D0
Line end to current position, DG
To delete a row:
Delete n rows down, NDD
Delete current line, DD

4) Copy and paste:
Copy:
Multiple lines: Nyy
Single-line partial character: a costume to the current cursor, y0; line tail to current cursor, y$
Paste:
Paste the next line under the cursor, p
Paste a line on the cursor, P
Note that when the copied content is a single-line partial character, p is pasted behind the current cursor and p is copied ahead of the cursor

5) Merger:
Merge current row and next row: J

6) Undo and Redo:
Undo: U
Redo: Ctrl + R

4. VI Insert mode:
1) Insert:
Current line:
Before the cursor, I;
Beginning of line, I;
Line break:
Previous line, O; next line, O
2) Replace:
Single replacement, R
Multiple substitutions, R (knowing ESC ends)

5. VI Command mode:
Save:: W
Exit:: Q
Forced exit:!
Save and exit if the file is changed, or do not exit: ZZ
Save As:: n1,n2 w filename. Where N1, N2 are the start and end lines respectively, and filename is saved as a file.

6. Vim's swap file processing:
Read-only, O
Recovery, R
Edit, E
Exit, Q
Abort, A
Note that the final swap file needs to be manually deleted.

7. Vim's block selection:
Rectangle, Ctrl + V
Line, V
Character, V
Copy, Y
Delete, D
Paste, p

8. Vim's multi-document:
Edit multiple files simultaneously: Vim T1 T2
List of File lists:: Files
File switching: Switch to the next file: N, switch to previous file: N
Note that when switching, you may be prompted to add! (Then do it: n! Just fine)

9. Vim's Multi-window:
Operation Steps:
Vim test
: SP [File] (if filled, opens new file for new window, otherwise the current file)
CTRL + W + j (switch to next window), CTRL + W +k (Switch to previous window)
CTRL + W + Q to save and exit the current window

Settings for VIM:
Show/Cancel line number:: Set Nu/:set Nonu (only current file current edit is set, next open or initial setting)
Permanent settings: Vim ~/.VIMRC
Vim system Operation record: ~/.viminfo

This article is from the "Inner Peace, Fire Rebirth" blog, please be sure to keep this source http://itisforyou.blog.51cto.com/9778869/1608577

VI and VIM's madness

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.