Xin Xing deeply analyzes vim's automatic complementing function and vim ing

Source: Internet
Author: User

Xin Xing deeply analyzes vim's automatic complementing function and vim ing

In the past, all the auto-completion functions of vim were downloaded from the Internet when needed, and copied to their own vimrc. I didn't know what it meant, the results show that many of the methods found to be auto-complete are quite different. Some prefer to use auto-wrap when the braces are fully filled, and others prefer to use auto-indent when the braces are fully filled, let's take a few minutes to understand how to write these configurations by ourselves. Why not?

* ******************************** Key ing ****** ************************

1. first, we need to distinguish between nnoremap and inoremap. The first is the ing that takes effect in normal mode, and the second is the ing that takes effect in insert mode, we generally need to use it in the insert mode. Therefore, we usually use inoremap. So what is ing?

2. The so-called ing means that when we press a key, it will execute another part of the content. For example, we use map T: q !, When we press T in command mode and press enter, We will exit vim. In addition to map, nmap also indicates that it takes effect in normal mode and imap takes effect in insert mode, vmap takes effect in visual mode and map takes effect in all modes.

3. Set a ing using map <ing key> <ing Key sequence>. If we want to unmap, run the unmap command to clear all mappings and run the mapclear command.

4. We usually write these mappings into the configuration file vimrc. Such a write takes effect permanently.

************ **********************

1. Any character that can be directly displayed can be directly entered, but there are two exceptions, namely, backslash and <, because we use backlash to indicate escape, and

2. The backslash is represented by two backslashes, or <Bslash>

3. <must be expressed by \ <or <lt>.

4. <key> indicates a special key. We will introduce some common special keys:

<Esc> Escape key,

<C-G> Ctrl-G key

<Up> indicates moving the cursor Up

<C-LeftMOuse> Ctrl and left-click

<Space> Space

<Tab> Table key

<CR> is the Enter key.

* ********************** Start to write our own Automatic completion *********** ************

1. First, I will provide my auto-completion format. First, it is worth noting that this code is written in _ vimrc. The following is a careful analysis:

"Auto-completion: inoremap () <ESC> I: inoremap) <c-r> = ClosePair (') <CR>: inoremap {<CR> <CR >}< ESC> 0ki <Tab>: inoremap} <c-r> = ClosePair ('}') <CR> function ClosePair (char) if getline ('. ') [col ('. ')-1] = a: charreturn "\ <Right>" else return a: char endif endf
2. here: inoremap indicates the ing in the insert mode. First, the second line (that is, write () first, and then return to the command mode using esc, then run I to enter the insert mode.

3. when I enter {, check its command. First, enter {, then <CR> to enter the line feed, then a line feed, and then enter }, then run esc to return to the command mode. Then run the 0 command to return to the beginning of the line. Then run the k Command to move the mouse over the previous line, and then run the I command to enter the insert mode, then we use <Tab> to insert a Tab.

4. Of course, I only define auto-Completions for parentheses and braces. I didn't use auto-Completions for brackets. You can modify them by yourself.

5. vim is quite comfortable to use at this point. After all, it feels very free.

6. Spread programming knowledge, revitalize Chinese software, Xin Xing, and look forward to your attention.

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.