"VIM" insert mode and common editing operations

Source: Internet
Author: User

Vim is not like many editors can directly edit the text as soon as possible, you need to press I in normal mode, a and other keys will enter the insertion mode for text editing.

How to enter Insert mode

The following commands will let vim switch from normal to insert mode, but the character insertion position after the command execution is different.

Command Character insertion position after execution
I Before the current character
I Before the first non-whitespace character at the beginning of the line
A After the current character
A Current end of line
S Deletes the current character, with the cursor resting at the next character
S Deletes the current line, and the cursor stops at the beginning
O Insert a new line below the current line, and the cursor stops at the beginning of the new line
O Inserts a new row above the current line, and the cursor stops at the beginning of the new line

Common editing operations

In the previous article, "Vim" normal mode of general operation has been mentioned, many operations in Vim can specify the number, range and direction, and editing operations are no exception. In order to be concise, the following table will not be the same as the previous one according to the action range of different classification (such as the word operation only give W, do not give w,e,e,b,b, etc.), but only give a few classic operations, the arrangement of the combination of examples in the next section to introduce some, specific changes or need to try and practice in practice.

Type
Command Description
Copy yw Copy a word after the cursor
Yy Copy when moving forward
<n>yy Copy the following n rows
YG Copy the contents of the current line to the end of the file
y%,ya{ Place the cursor on {, copy the contents of {} and its interior
Cut/Delete X Cuts the current character, equivalent to DL
X Cut the previous character, equivalent to DH
DW,CW A word after the cursor is cut, the difference between D and C is that C will go into insert mode, the same as
D, C Cut to the end of the line, equivalent to d$,c$
DD,cc Cut when moving forward
<n>dd,<n>cc Cut the following n rows
Dg Cuts the current line to the end of the file
Paste P Paste the contents of the Clipboard after the cursor
P Paste the contents of the Clipboard before the cursor
Replace R After pressing, the character will be replaced by the current character.
R After pressing, enter replace mode, followed by the character
Revoke U
Redo <ctrl>+r
Indent in >> Indents the current line to the right
<< Indent the current line to the left
<n>>> The following n lines indent to the right
<n><< The following n lines indent to the left
== Automatically adjusts the indentation of the current line to the context
<n>== Automatically adjusts the indentation of the following n lines
Gg=g Auto-adjust indentation for all lines of a file
Convert case ~ Converts the case of the current character
Guw Turn the word after the cursor all lowercase
Guw Capitalize all words after the cursor
Guu Turn the current line all lowercase
GUU Make the current line all uppercase
Block Comment * Comments

If you want to comment out the contents of line 8th through 16th, the step is
1. The cursor is positioned to the beginning of line 8th
2. Press <ctrl>+v to enter visual mode (visual Block)
3. Press the J or down arrow to locate the beginning of line 16th
4. Press <shift>+i, enter//
5. Press once or two times <Esc>

Cancel Comment

If you want to uncomment the contents of line 8th through line 16th with//, the step is
1. The cursor is positioned to the beginning of line 8th
2. Press <ctrl>+v to enter visual mode (visual Block)
3. Press the J or down arrow to locate the beginning of line 16th, press L or right arrow, select//
4. Press D or X to delete//

* The block annotation used in the visual mode of operation, which should be described in a later article, but this operation is very important, so here to introduce. Uncomment 3rd step to the beginning of line 16th and move right to select//two actions, which can be interchanged.

Combination Command Example

y3w 3 words after copying a cursor
d2$ cut the cursor to the end of line 2nd below
} Indents the content between the current line and the next blank line to the right
=% the cursor on {or} and automatically indents the contents of the middle of {} after execution
3gUU Capitalize all of the following 3 lines
dt<c> in the current row, delete the 1th character <c> from the cursor

Infrequently-Used editing operations

.(decimal point) You can repeat the last command
<n><Command> Repeat a command n times
: r!date Insert Date

"VIM" insert mode and common editing operations

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.