My vim has path settings as shown below.
我的vim有如下所示的路径设置。
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.
因此,gf在游标下打开c头文件。
But on C++ file C++ header files are not opened because the C++ header file location is not added to path
variable of vim.
但是在c++文件中,c++头文件没有被打开,因为c++头文件的位置没有被添加到vim的path变量中。
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.
我认为vimrc上的设置是一个解决方案。但是问题是,在每个不同的linux发行版和g++编译器版本中,c++头文件的实际目录位置将被更改。
How can I set path for c++ header files in a portable manner?
如何以可移植的方式设置c++头文件的路径?
2 个解决方案
#1
8
If there's a limited number of locations, a simple conditional in ~/.vimrc
will do:
如果有有限的位置,一个简单的条件在~/中。vimrc会做的事:
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:
如果您有很多不同的系统,并且不想在中心位置维护所有的变体,那么您可以将系统相关的设置移动到一个单独的本地文件中,并从~/中调用它。vimrc,像这样:
" Source system-specific .vimrc first.
if filereadable(expand('~/local/.vimrc'))
source ~/local/.vimrc
endif
#2
-2
There are specific environment variables for the compiler to examine. If you are using gcc/g++ in a linux/Unix environment, then the variables are C_INCLUDE_PATH
and CPLUS_INCLUDE_PATH
. If you are using bash/sh then use export VARIABLE=value
or if you are using csh/tcsh then use setenv VARIABLE value
or if you are using some other shell then you will need to look that up. In these examples VARIABLE
is either C_INCLUDE_PATH
and CPLUS_INCLUDE_PATH
. I hope this helps.
有特定的环境变量供编译器检查。如果您在linux/Unix环境中使用gcc/g++,那么变量是C_INCLUDE_PATH和CPLUS_INCLUDE_PATH。如果您使用bash/sh,那么使用export变量=值,或者如果您使用csh/tcsh,那么使用setenv变量值,或者如果您正在使用其他shell,那么您将需要查找该值。在这些示例中,变量是C_INCLUDE_PATH和CPLUS_INCLUDE_PATH。我希望这可以帮助。
#1
8
If there's a limited number of locations, a simple conditional in ~/.vimrc
will do:
如果有有限的位置,一个简单的条件在~/中。vimrc会做的事:
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:
如果您有很多不同的系统,并且不想在中心位置维护所有的变体,那么您可以将系统相关的设置移动到一个单独的本地文件中,并从~/中调用它。vimrc,像这样:
" Source system-specific .vimrc first.
if filereadable(expand('~/local/.vimrc'))
source ~/local/.vimrc
endif
#2
-2
There are specific environment variables for the compiler to examine. If you are using gcc/g++ in a linux/Unix environment, then the variables are C_INCLUDE_PATH
and CPLUS_INCLUDE_PATH
. If you are using bash/sh then use export VARIABLE=value
or if you are using csh/tcsh then use setenv VARIABLE value
or if you are using some other shell then you will need to look that up. In these examples VARIABLE
is either C_INCLUDE_PATH
and CPLUS_INCLUDE_PATH
. I hope this helps.
有特定的环境变量供编译器检查。如果您在linux/Unix环境中使用gcc/g++,那么变量是C_INCLUDE_PATH和CPLUS_INCLUDE_PATH。如果您使用bash/sh,那么使用export变量=值,或者如果您使用csh/tcsh,那么使用setenv变量值,或者如果您正在使用其他shell,那么您将需要查找该值。在这些示例中,变量是C_INCLUDE_PATH和CPLUS_INCLUDE_PATH。我希望这可以帮助。