Vim autocomplete from ctags for system headers only works when starting the popup manually

On OS X, I generated a set of ctags for the system using the following command:

ctags -f c -h ".h" -R --c-kinds=+p --fields=+iaS --extra=+q /usr/include

      

This was run inside a directory ~/.vim/ctags/

where I put all the ctags I generate for the system wide header files (I also have stuff for ROS and CPP that I conditionally download, but which are neither here nor there).

Anyway. The ctags file is set correctly in my .vimrc, and vim can definitely see the ctags, but for some reason the autocomplete popup will only show the results from the #include

d header files if I write out the entire character and then start the reverse swap. As an example, if I am #include <string.h>

in a project and then I want to invoke strlen()

and I start typing str

into the vim active buffer, I only get results for the characters that are currently in vim. But, if I type strlen

and then start to return one or two characters and click <C-n>

, the popup menu will be filled with matches from any other included header files.

EDIT: It turns out if I just press "s" then <C-n>

, it works as well. So the problem is that it only works if the popup menu is started manually. This makes me think it is a plugin issue (see below)

Additional Information:

  • completeopt

    set on completeopt=menuone,menu,preview,longest

  • I have an OmniCppComplete which I suppose might interfere with the behavior. Currently not not only loaded for C ++ files. If you'd like me to edit and post my OmniCppComplete settings from my .vimrc, just ask.

  • I also have AutoComplPop , but I haven't done anything to configure it, so it works with its default settings. Didn't actually investigate the plugin, so I don't know if some behavior might affect the results.

  • I have AutoTag and TagBar , but they should only work with the current directory of the local tags file.

I'm honestly new to Vim and I just don't know where to start debugging this issue, whether with a random plugin or with .vimrc settings.

+3


source to share


2 answers


Vim has many special completion mechanisms.

  • <C-n>

    and <C-p>

    use many sources defined by the option complete

    . By default, they will complete the completion using the current and all loaded and unloaded buffers, tags, and included files. While you can usually get some pretty useful suggestions with them, this is a bit of a "comprehensive" solution: it is not reliable at all if you are working on large enough projects.

  • <C-x><C-]>

    uses only tags, so you might find it a little more useful.

  • And there are many more, see :h ins-completion

    .

  • Omni's execution is smarter: it usually runs a custom file-type-specific script that tries the hard way to make it complete. It works <C-x><C-o>

    and you can read about it in :h ft-c-omni

    . Omni completion is generally the best choice when working with code.



Since you have two overlapping "auto" bundling plugins, it's hard to tell which completion mechanism is working. You should disable these plugins and play with the various completion mechanisms available to you.

+3


source


I haven't mastered this yet, but I think the following observation might be helpful.

Vim's default autocomplete, which can be quite noisy, often gets in the way of what you call with <C-x><C-o>

. In particular, I found that I end up completing my based tags <C-x><C-o>

only to replace them with input continuation with Vim's default suggestions using my open buffers.

The suggestion to disable one of the plugins makes sense. In my case, the key was how to close Vim's default behavior. I've seen several people (and to which I am now including myself) set the length of an expression to a large number before starting Vim by default. For me it:

    let g:deoplete#auto_complete_start_length = 99

      



... that way you remove the default level that comes and goes, regardless of the commands you wanted to communicate to your work.

This still looks like a hack, but it helps me focus on completing tags.

FYI: I am using NVIM on Mac.

0


source







All Articles