path setting for c++ include headers for vim
c++, include, path, vim
Solution
If there's a limited number of locations, a simple conditional in `~/.vimrc` will do:
if isdirectory('/usr/include/c++/4.6')
set path+=/usr/include/c++/4.6
elseif isdirectory(...
If you have a lot of different systems, and don't want to maintain all variations in a central place, you can move the system-dependent settings to a separate, local-only file, and invoke that from your `~/.vimrc`, like this:
" Source system-specific .vimrc first.
if filereadable(expand('~/local/.vimrc'))
source ~/local/.vimrc
endif
Problem
My vim has path settings as shown below. ``` path=.,/usr/include,, ``` I think this is a default setting of 'path' I guess. Because of this, g f opens c header files under the cursor. But on C++ file C++ header files are not opened because the C++ header file location is not added to `path` variable of vim. ``` set path+=/usr/include/c++/4.6 ``` I think that this setting on `vimrc` would be a solution. But the problem is the actual directory location for C++ header file would be changed in every different linux distributions and g++ compiler versions. How can I set path for c++ header files in a portable manner? ``` let g:gcpp_headers_path = system("g++ --version | grep g++ | awk '{print \"/usr/include/c++/\"$NF}'") execute 'set path+=' . g:gcpp_headers_path ``` Now I am using this above: This works with g++ environment. Not tested with other compilers.