首先,你必须设置:h 'path',这样Vim 才能找到pthread.h。从 gcc/clang 设置 path 的示例代码(取自 my config):
" gcc_include([{gcc} [, {force} [, {ft}]]])
" get GCC include dirs
function s:gcc_include(gcc = 'gcc', force = 0, ft = &filetype) abort
if a:force || !has_key(s:, 'gcc_include_' . a:ft)
" $INCLUDE
let s:gcc_include_{a:ft} = split($INCLUDE, has('win32') ? ';' : ':')
" builtin dirs
let l:cmd = printf('%s -x%s -v -E -', a:gcc, a:ft is# 'cpp' ? 'c++' : a:ft)
let l:include = map(systemlist(l:cmd, []), 'trim(v:val)')
let l:ix1 = match(l:include, '#include <\.\.\.>') + 1
let l:ix2 = match(l:include, '\.$', l:ix1) - 1
if l:ix1 <= l:ix2
let s:gcc_include_{a:ft} += map(l:include[l:ix1 : l:ix2], 'simplify(v:val)')
endif
endif
return s:gcc_include_{a:ft}
endfunction
" :GccInclude[!] [/path/to/gcc]
" set local &path to GCC include dirs
command! -bar -bang -nargs=? -complete=file GccInclude let &l:path = join(['.'] +
\ s:gcc_include(empty(<q-args>) ? 'gcc' : <q-args>, <bang>0) + [','], ',')
当yourfile.c 处于活动状态时,运行:GccInclude clang 并确保:set path? 显示有意义的内容。
之后你可以使用:h include-search下的任何东西,例如,将光标移动到“pthread_t”并按Ctrl-WCtrl-I。 p>
请注意,它是纯内置功能,因此有时 Vim 可能无法正确解析 C 代码。