The four modes of VIM technique _ Insert Mode

Source: Internet
Author: User
Tags sublime text

    • The four modes of VIM technique _ Insert Mode
    • Correcting errors in insert mode in a timely manner
    • Insert-Normal mode
    • Paste the contents of the specified register directly under Insert mode mode
    • Doing operations in insert mode
    • Inserting very useful characters with character encoding
    • Replace existing text

The four modes of VIM technique _ Insert Mode

In the previous article, "Four modes of VIM skills _ Normal mode," we mentioned that one of the four models of the normal mode, today we continue to talk about Vim the four modes of insertion mode

Normal mode is like launching a skill, while the insertion mode is a general physical attack, but it is a light physical attack, there are a lot of tricks to say

Correcting errors in insert mode in a timely manner

In Normal mode , we have a number of ways to change the input of an error, we can directly click u to undo the previous type of content, we can also use, and so on the caw ciw cb command to make the wrong input timely changes, but if we In the Insert mode you want to change the wrong input in a timely manner, but <Backspace> there is no other way?

In many popular editors, for example, Emacs if you Sublime Text find an input error, you can delete the <C-Backspace> previous word, and you Emacs can delete the entire row of data in the cursor, but is there any <C-k> Vim such handy operation in it?

Key Operation function
<C-h>(Backspace) Delete the previous character
<C-w> Delete a previous word
<C-u> Delete to the beginning of the line

Master the above skills, you can quickly change the data without going back to Normal mode .

Insert-Normal mode

In some cases of insert mode We just want to execute a command in Normal mode , and then continue to enter data, we can use <C-o> to return to Normal mode , after executing a command, will immediately return to insert mode . (Personally, I prefer direct <ESC> )

For example, if you are editing text, you need to center the text of the line you are editing ( zz ) or the top ( zt ), you can do it <C-o>zz .

Paste the contents of the specified register directly under Insert mode mode

First of all, we need to know what Vim registers, Vim The register as the name implies is used to store some specific data or user-defined data, when we need to directly access the register, in the Vim input :reg to view the contents of the Register

You can see a variety of registers, if you want to know the Vim register, please see here VIM Register use detailed

For example, the more commonly used in the digital register "[0-9] , the Vim copied data is saved to the Register "0 , the latest deleted data is saved to the "1 old deleted data will be moved from the previous register to the next register, such as when the new data is deleted, The data of the register will be transferred to the "1 register "2 , "2 transferred to, and so on, "3 and finally the new delete data will be saved "1 in.

Sometimes we want to paste the previously deleted data (not the latest deleted data), this time the use p is obviously not possible, because p only paste the latest deleted or copied data, then deleted the data disappeared? In Vim fact, we will save nine delete operation data, as long as you type in the insert mode <C-r>{register} can be pasted in register the data, in Normal mode for"{register}p

Give me a chestnut:

We have the following text:

Look at what's in the register.

We're going to paste "8 the register data,<C-r>8

Attention:
Using the <C-r>{register} pasted data will preserve the indented format of the original data, and if you set up testwidth or are autoindent , then there may be unnecessary indentation. Then you need to use <C-r><C-p>{register} the simple insert data, without any indentation

Doing operations in insert mode

If we need to do some simple operations in the Insert mode, we can use the expression register directly "= to calculate our expression and insert the result, specifically <C-r>={expression}<CR> , where expression we need to calculate the formula, for example 1+2 , 10*6 ...

Give me a chestnut:

We type two expressions:

Complete basic calculations with expression registers
<C-r>=5+12<CR>
<C-r>=6*78<CR>

Inserting very useful characters with character encoding

As long as we know the encoding of a character, we Vim can insert the character directly, we can insert the corresponding character in the insert mode, <C-v>{code} code For example, we <C-v>065 can insert uppercase letters.‘A‘

Conversely, if you want to know the encoding of a character, you can move the cursor over that character and enter it, and the ga character's encoding will appear below the screen.

Replace existing text

In the Vim , if you want to type a new text to replace the original text, then R and r These two commands you need to know

Command function
R Replace text at the cursor until you press<ESC>
r Replaces the current one character

give me a chestnut:

To change the above Vimer loser , we can change the
0 (move to the beginning of the sentence)
FV (move to the beginning of the Vimer word)
Rlos (will be Vim replaced los )

Attention:
When we use a substitution, we Vim take a tab with a plurality of space widths as a replacement character, so we have a variety of indents that we do not want to appear in when we replace them, not aligned. To avoid this, we can use gR or gr command to do the substitution operation, in gR and gr Replace, the Vim tab as a set of spaces to handle, the specific number of spaces to be used by the tab space to determine the width, This substitution becomes a virtual replacement mode.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The four modes of VIM technique _ Insert Mode

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.