"Linux Learning Notes" VIM command summary __linux

Source: Internet
Author: User
Tags comments

VI Editor has 3 kinds of modes: Command mode, input mode, last line mode. It is important to master these three models:

Command mode: VI after the start of the default to enter the command mode, from this mode using the command can switch to the other two modes, and no matter in any mode, just click the [ESC] key can return command mode. Enter the subtitle "I" in the command mode to enter the VI input mode to edit the file.

Input mode: In this mode we can edit, modify, input and other editing work, in the last line of the editor shows a "--insert--" marked VI into the input mode. We need to save the file when we finish modifying the input, and then we need to return to the command mode and save it in the last line mode.

Last line mode: In the command mode input ":" Can enter the mode, in the last line mode has a lot of useful commands.

Edit action
Enter input mode command
I insert command a additional command o Open command C Modify command
R replaces command s replace command ESC exit command

Operation of input mode
Home cursor to beginning of line (^)
End cursor to End-of-line ($)
Page up and PAGE down page down
Delect Delete the character of the cursor position

Delete operation (Command mode use)
x deletes a single character at the cursor
DD deletes the cursor in the row
DW deletes all characters from the current character to the end of the word including spaces
#x例如3x删除光标处向右的三个字符
#dd例如3dd从当前行开始向下删除三行文本

Delete all:

1.gg back to file start-->DG

2.G to end of file: 1,.d ("." represents the current line)

3. Finally, the simplification is:: 1, $d




Undo Action
The U command cancels the most recent operation and can be used several times to restore the original operation
U Cancel all operations
Ctrl+r can revert to operations using the U command

Copy operation
YY command Copy current entire line contents to VI buffer
YW copy the current cursor position to the end of the word character content to the vi buffer, the equivalent of copying a word
y$ copy cursor position to line end content to buffer
y^ copy cursor position to header content to buffer
#yy例如: 5yy is to copy 5 lines
#yw例如: 2yw is a copy of two words

If you want to copy the content between rows m and N, you can enter M,ny in the last row mode for example: 3,5y Copy the third row to the fifth line to the buffer.

Find and replace
VI's search and replace function is mainly completed in the last line mode:

The first and bottom search
/To find the character of the channeling, where/representative starting from the location of the cursor, such as:/work

Lookup up to bottom
。 To find the character channeling for example:? work

Replace
: S/old/new replaces the first occurrence of old in a row with new
: S/old/new/g replaces all occurrences of the old in the row with new
: #,# s/old/new/g replaces the old from line # to line # with new
:% s/old/new/g replaces old in whole article with new

If the replacement range is large, add a C command at the end of all commands, forcing each replacement to require the user to confirm, for example: S/OLD/NEW/C or S/OLD/NEW/GC

Comments

1. Multi-line Comment:

1. First press ESC to enter the command line mode, press CTRL + V, enter the column (also called block) mode;   2. Use the Up-down key at the beginning of the line to select multiple lines to annotate; 3. Press the keyboard (uppercase) "I" key to enter the insertion mode; 4.   Then enter the annotation character ("//", "#", etc.); 5. Finally press the "ESC" key.
Note: When the ESC key is pressed, it will wait a little while to appear, don't worry ~ ~ Time is very short 2. Delete Multiline comments: 1.   First press ESC to enter the command line mode, press CTRL + V to enter the column mode;   2. Select multiple lines to uncomment; 3. Press "X" or "D".
Note: If it is a "//" note, it needs to be done twice, if it is a "#" note, once
 

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.