git.vim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. " Vim filetype plugin
  2. " Language: generic git output
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2016 Aug 29
  5. " Only do this when not done yet for this buffer
  6. if (exists("b:did_ftplugin"))
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. if !exists('b:git_dir')
  11. if expand('%:p') =~# '[\/]\.git[\/]modules[\/]'
  12. " Stay out of the way
  13. elseif expand('%:p') =~# '[\/]\.git[\/]worktrees'
  14. let b:git_dir = matchstr(expand('%:p'),'.*\.git[\/]worktrees[\/][^\/]\+\>')
  15. elseif expand('%:p') =~# '\.git\>'
  16. let b:git_dir = matchstr(expand('%:p'),'.*\.git\>')
  17. elseif $GIT_DIR != ''
  18. let b:git_dir = $GIT_DIR
  19. endif
  20. if (has('win32') || has('win64')) && exists('b:git_dir')
  21. let b:git_dir = substitute(b:git_dir,'\\','/','g')
  22. endif
  23. endif
  24. if exists('*shellescape') && exists('b:git_dir') && b:git_dir != ''
  25. if b:git_dir =~# '/\.git$' " Not a bare repository
  26. let &l:path = escape(fnamemodify(b:git_dir,':h'),'\, ').','.&l:path
  27. endif
  28. let &l:path = escape(b:git_dir,'\, ').','.&l:path
  29. let &l:keywordprg = 'git --git-dir='.shellescape(b:git_dir).' show'
  30. else
  31. setlocal keywordprg=git\ show
  32. endif
  33. if has('gui_running')
  34. let &l:keywordprg = substitute(&l:keywordprg,'^git\>','git --no-pager','')
  35. endif
  36. setlocal includeexpr=substitute(v:fname,'^[^/]\\+/','','')
  37. let b:undo_ftplugin = "setl keywordprg< path< includeexpr<"