I use vim on Linux and Windows. Strangely, on Linux (Ubuntu), when I write C/C++ code, vim would search the included file for auto-completion (Ctrl-P), even if I don't add anything related in my .vimrc
. But on Windows, it doesn't behave that way. I have tried to add set path+=$INCLUDE
in my _vimrc
($INCLUDE
is in my path and it's the path of the C/C++ header file), but that doesn't work either.
1 Answer
with the help from VanLaser in the comments above,I eventually find out how to do that on Windows:
set path+=C:/Program\\\ Files\\\ (x86)/Microsoft\\\ Visual\\\ Studio\\\ 12.0/VC/include
set path+=C:/Program\\\ Files\\\ (x86)/Microsoft\\\ SDKs/Windows/v7.1A/Include
just add these two lines in my vimrc then it would work. Those two C:/xxxxx
are my system %INCLUDE%
path, where all the necessary C/C++ header files located. Note the different version of Visual Studio and change those two path correspondingly. Also note that those \\\
are necessary to escaped the space(see :h 'complete'
(not :h complete()
) for more information).
Also, make sure that option i
is in your complete options(use set complete?
to see, and the default is complete=.,w,b,u,t,i
. See :h 'complete'
)
-
If you don't like the triple slashes you could also do
let &path = path . ',C:/Program Files (x86)...,C:/...'
, using a single quoted literal string after alet
with string concatenation. The two C: bits are your two paths and there's a comma separating each path including these from what's existing. Mar 1, 2016 at 4:34
:set complete?
? If there is noi
for searching included files for autocompletion, addingset complete+=i
in your_vimrc
might help. Does your problem happen with exactly the samevimrc
file on Linux and Windows? Also, do you by chance happen to use tpope's sensible.vim?behave mswin
. But besides those operating-system related directives, all other are the same. And I am not usingsensible.vim
. Have you ever had the same problem?$INCLUDE
, and that path is not the path to the file, but to the include folder? An equivalent to Linux's/usr/include
path. Things should be OK when you can place cursor on a line such as#include <stdio.h>
andgf
can open that file.