13

I'm brushing up on my vim skills and fiddling with completion using the Ctrl-n command. I'm programming in Perl. When I am in insert mode and hit Ctrl-n, I get a message that it is "Scanning included file" down at the bottom of the terminal and it looks like it's scanning files in the perl distribution directories. This can take several seconds before it finishes. It looks like it does this with packages I include that are commented out:

#use Moose;

So I have to delete these lines for this feature to be of any value. Am I missing something?

I am using the perl-support plugin.

  • I tried something like this in .vimrc but it had on effect: let g:ctrlp_custom_ignore = { 'dir': '^/usr/' } let g:ctrln_custom_ignore = { 'dir': '^/usr/' } – StevieD Feb 11 '17 at 17:12
11

By default, when you hit C-n or C-p, Vim looks inside various sources to find candidates which will populate the completion menu.

These sources can be configured with the buffer-local 'complete' option.

The value of this option is a comma-separated list of flags. Each flag has its own meaning described in :h 'cpt:

.   scan the current buffer ('wrapscan' is ignored)
w   scan buffers from other windows
b   scan other loaded buffers that are in the buffer list
u   scan the unloaded buffers that are in the buffer list
U   scan the buffers that are not in the buffer list
k   scan the files given with the 'dictionary' option
kspell  use the currently active spell checking |spell|
k{dict} scan the file {dict}.  Several "k" flags can be given, patterns are valid too.  For example:  
        :set cpt=k/usr/dict/*,k~/spanish
s   scan the files given with the 'thesaurus' option
s{tsr}  scan the file {tsr}.  Several "s" flags can be given, patterns are valid too.
i   scan current and included files
d   scan current and included files for defined name or macro |i_CTRL-X_CTRL-D|
]   tag completion
t   same as "]"

By default, its value is .,w,b,u,t,i, which means:

   1. the current buffer
   2. buffers in other windows
   3. other loaded buffers
   4. unloaded buffers
   5. tags
   6. included files

If you find that scanning the included files takes too much time, you could try to remove the i flag from the 'cpt' option.

If you wanted to remove it from the global value, to affect all the buffers by default, you would write in your vimrc:

setglobal complete-=i

If you wanted to do the same thing, but only for perl files, you could install an autocmd inside your vimrc:

augroup PerlSettings
    autocmd!
    autocmd FileType perl setlocal complete-=i
augroup END

Or better, you could create a filetype plugin, for example in ~/.vim/after/ftplugin/perl.vim, in which you would simply write:

setlocal complete-=i

To check out what's the current global and local values of your 'complete' option, and where they were last set, you could use these commands:

verbose setglobal complete?
verbose setlocal complete?

Or shorter:

verb setg cpt?
verb setl cpt?

If the only source in which you're interested is the current buffer, then, instead of using C-n, you could use C-x C-n. See :h i_^x^n for more info.

  • 1
    Is there a way to exclude keywords in files in certain paths? – StevieD Feb 19 '17 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.