问题
I want to set vim file search path to include git repository root (which can be found by git rev-parse --show-toplevel). I can't figure out how to append the output of this git command to "set path=.,,**" in .vimrc.
Thanks!
回答1:
You can use this command:
let &path .= "," . system("git rev-parse --show-toplevel | tr -d '\\n'")
That said, I usually start Vim from the top-level directory of the project and never change the working directory so that's one less setting to worry about.
See :help system() and :help :let
回答2:
" Add the git dir only once, and check for errors.
function! MoshGitPath()
let g:gitdir=substitute(system("git rev-parse --show-toplevel 2>&1 | grep -v fatal:"),'\n','','g')
if g:gitdir != '' && isdirectory(g:gitdir) && index(split(&path, ","),g:gitdir) < 0
exe "set path+=".g:gitdir."/*"
endif
endfunction
command! MoshGitPath :call MoshGitPath()
:MoshGitPath
来源:https://stackoverflow.com/questions/30171512/how-to-set-the-root-of-git-repository-to-vi-vim-find-path