Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active September 17, 2025 13:59
Show Gist options
  • Save Konfekt/13bbdb8280be603089163e5b2b59fd97 to your computer and use it in GitHub Desktop.
Save Konfekt/13bbdb8280be603089163e5b2b59fd97 to your computer and use it in GitHub Desktop.
set vim path using git ls-tree
let s:nul = ' 2> ' .. (has('win32') ? 'nul' : '/dev/null')
function! s:outside_repo() abort
if exists('*FugitiveGitDir')
return empty(FugitiveGitDir())
else
" let outside_repo = empty(finddir('.git', getcwd().';')) && empty(findfile('.git', getcwd().';'))
silent let repo = system('git rev-parse --is-inside-work-tree' .. s:nul .. ' 1>&2')
return v:shell_error != 0
endif
endfunction
let s:path = &g:path
function! s:SetPath() abort
if s:outside_repo() | return | endif
silent let paths = join(systemlist('git ls-tree -d --name-only -r HEAD' .. s:nul), ',')
let &g:path = s:path .. ',' .. paths
endfunction
autocmd vimrc VimEnter,DirChanged * call <SID>SetPath()
@Konfekt
Copy link
Author

Konfekt commented Sep 17, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment