Vim's ultimate auto-completion plug-in: neocomplcache

Source: Internet
Author: User
Tags keyword list

Copyright ownership: qinggeng Yu @ [mu Zhizhi]. If you need to renew your account, please indicate the location.
Original address: http://0x3f.org /? P = 1399

With regard to auto-completion, supertab was initially used. At that time, there were few Vim auto-completion plug-ins, and supertab was quite famous. However, in actual use, this plug-in does not give me a good experience, because the accuracy of completion is not high.

Later, a new plug-in named autocomplpop was developed, which has simple functions and usage. However, soon I used supertab again, because autocomplpop queries matching keywords in real time while inputting, resulting in extremely poor input and low efficiency.

Supertab has always been used in this way. With the update of this plug-in version, the old features are constantly improved and new features are introduced one after another. supertab improves the accuracy of matching keywords, but new problems have emerged. Supertab then added a new function. For program source files, you can match keywords in the imported files and API files. For example, if I am editing a. phpInclude 'B. php ';When I enter such a statementArrayWhen you press the tab key, supertab not only queries all matching items in the current file, but also goes to B. PHP query. If Vim is configured and a file containing php apis is specified, supertab automatically queries matching items from this file. It is reasonable to say that this function has a good idea, but the problem is that supertab performs real-time queries. If the source file contains many files and each file is large, the problem becomes obvious. I have to use the tab key carefully when writing a program. Otherwise, sometimes I press the tab key and wait for VIM to search for it.

I found neocomplcache two days ago. I am a little excited when I look at the name. Generally, the cache speed is very fast. This plug-in will create an index on the context when Vim opens the file and save the index results to the cache. At the same time, the file changes will be indexed during storage. In addition, neocomplcache supports multiple keyword indexing modes. For example, it determines whether the file or directory name in the current path matches the completion condition, or it can match the completion condition from the cached program language API. So far, it solves the common efficiency problems of supertab and autocomplpop, and has their respective strengths. After reading the document, I found that the plug-in has the following features:

1. High auto-completion timeliness when cache is used;
2. The generated keyword list is accurate;
3. keywords that support underline separation, such as apple_boy_cat, can be entered only a_ B _c and supplemented;
4. Supports keyword matching in the hump format, such as appleboycat. You can enter ABC and complete the input;
5. You can enter the complete list in VIM like autocomplpop, and manually trigger a custom shortcut key;
6. Support matching the completion condition from the file name and directory name;
7. For program source files, the language API supports matching the completion condition;

The disadvantage of neocomplcache is that the documentation is incomplete. Although it is found from a few words that it also supports snippet, it does not find enough useful information from the document. In addition, snipmate has always been used, so it is still used to implement the snippet function.

There is a matching problem: Although neocomplcache does not have a full-time efficiency problem, I still intend to use the shortcut key to trigger this function only when I need to complete the full time, the main reason is that I want to use the tab key to trigger the snipmate code block complementing function, and use the tab to select the options in the Completion list. That is to say, you can enable the auto-Completion list, the selection of the complete list option, and the replacement of the snipmate code block by using the tab key. However, if you map the tab to trigger auto-completion, neither the complete list selection nor snipmate can use the tab, and vice versa.

So I think if we can make neocomplcache, supertab, and snipmate coexist harmoniously, the problem will be solved. After several explorations, I finally found a solution:

1. When neocomplcache is set, the Completion list is not automatically displayed, that is, add the following to vimrc:

Let G: neocomplcache_disableautocomplete = 1

2. Because neocomplcache uses a shortcut key combination in manual mode<C-X><C-U>Open the Completion list, so the default completion operation for supertab is<C-X><C-U>In vimrc:

Let G: supertabdefacomplecompletiontype ='<C-X><C-U>'

In this way, neocomplcache is only responsible for generating the completion keyword cache. supertab controls the tab key behavior and enables the Completion list when the completion operation needs to be triggered, so as to move the focus between options in the list, when the key word before the cursor is snippet, snipmate will be called first and the code block will be replaced.

When I was writing this article, I suddenly felt that neocomplcache automatically popped up the Completion list + snipmate method is also quite good, but in this way, the option in the list cannot be selected using the tab key.

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.