Paths for C ++ include headers for vim

My vim has path settings as shown below.

path=.,/usr/include,, 

I think this is the default value for the "path". I guess.

Because of this, g f opens c header files under the cursor.

But in the C ++ file, the C ++ header files do not open because the location of the C ++ header file is not added to the path vim variable.

 set path+=/usr/include/c++/4.6 

I think this setup on vimrc will be the solution. But the problem is that the actual directory location for the C ++ header file will be changed in every other Linux distribution and in g ++ compiler versions.

How to set the path for C ++ header files in a portable way?

+8
c ++ include vim path
source share
2 answers

If there is a limited number of places, a simple condition in ~/.vimrc will fulfill:

 if isdirectory('/usr/include/c++/4.6') set path+=/usr/include/c++/4.6 elseif isdirectory(... 

If you have many different systems and you do not want to support all the options in a central place, you can move the system-dependent parameters to a separate local type file and call this from your ~/.vimrc , for example:

 " Source system-specific .vimrc first. if filereadable(expand('~/local/.vimrc')) source ~/local/.vimrc endif 
+7
source share

There are special environment variables for checking by the compiler. If you are using gcc / g ++ on a linux / Unix environment, the variables are C_INCLUDE_PATH and CPLUS_INCLUDE_PATH . If you use bash / sh, then use export VARIABLE=value , or if you use csh / tcsh, use setenv VARIABLE value or if you use any other shell, then you will need to look at it. In these examples, VARIABLE is set to C_INCLUDE_PATH and CPLUS_INCLUDE_PATH . Hope this helps.

-one
source share

All Articles