Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict vim auto completion to search current file only?

Tags:

vim

ctrl+n and ctrl+p is very convenient completion for Vim, but sometimes it is very slow which may be caused that too many included header file in the current sources. Is there an option to restrict auto completion to search current source file (or opened streams) only?

like image 591
Thomson Avatar asked Jul 10 '14 14:07

Thomson


2 Answers

You have to play around with the complete option.

From the help file,

The default is ".,w,b,u,t,i", which means to scan:
   1. the current buffer
   2. buffers in other windows
   3. other loaded buffers
   4. unloaded buffers
   5. tags
   6. included files

Personally, I have noted that removing included files was really helpful, so, in my .vimrc, I use:

set complete-=i

But you can remove (or add) other lists as well.

See :help 'complete' for more information.

like image 75
Xavier T. Avatar answered Sep 19 '22 12:09

Xavier T.


If you have a feeling for when this "sometimes" is (a large project, a complex C file with many includes, ...), you can also use the <C-x><C-n> local file completion, see :help i_CTRL-X_CTRL-N. This way, you still have the default completion available and don't need to mess with the 'complete' option.

like image 20
Ingo Karkat Avatar answered Sep 19 '22 12:09

Ingo Karkat