dirvish.vim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. if exists('g:loaded_dirvish') || &cp || v:version < 700 || &cpo =~# 'C'
  2. finish
  3. endif
  4. let g:loaded_dirvish = 1
  5. command! -bar -nargs=? -complete=dir Dirvish call dirvish#open(<q-args>)
  6. command! -nargs=* -complete=file -range -bang Shdo call dirvish#shdo(<bang>0 ? argv() : getline(<line1>, <line2>), <q-args>)
  7. func! s:isdir(dir)
  8. if &l:bufhidden =~# '\vunload|delete|wipe'
  9. return 0 " In a temporary special buffer (likely from a plugin).
  10. endif
  11. return !empty(a:dir) && (isdirectory(a:dir) ||
  12. \ (!empty($SYSTEMDRIVE) && isdirectory('/'.tolower($SYSTEMDRIVE[0]).a:dir)))
  13. endf
  14. augroup dirvish
  15. autocmd!
  16. " Remove netrw and NERDTree directory handlers.
  17. autocmd VimEnter * if exists('#FileExplorer') | exe 'au! FileExplorer *' | endif
  18. autocmd VimEnter * if exists('#NERDTreeHijackNetrw') | exe 'au! NERDTreeHijackNetrw *' | endif
  19. autocmd BufEnter * if !exists('b:dirvish') && <SID>isdir(expand('%:p'))
  20. \ | Dirvish
  21. \ | elseif exists('b:dirvish') && &buflisted && bufnr('$') > 1 | setlocal nobuflisted | endif
  22. autocmd FileType dirvish if exists('#fugitive') | call FugitiveDetect(@%) | endif
  23. autocmd ShellCmdPost * if exists('b:dirvish') | Dirvish | endif
  24. augroup END
  25. nnoremap <silent> <Plug>(dirvish_up) :<C-U>exe 'Dirvish' fnameescape(fnamemodify(@%, ':p'.(@%[-1:]=~'[\\/]'?':h':'').repeat(':h',v:count1)))<CR>
  26. nnoremap <silent> <Plug>(dirvish_split_up) :<C-U>split<bar>exe 'Dirvish' fnameescape(fnamemodify(@%, ':p'.(@%[-1:]=~'[\\/]'?':h':'').repeat(':h',v:count1)))<CR>
  27. nnoremap <silent> <Plug>(dirvish_vsplit_up) :<C-U>vsplit<bar>exe 'Dirvish' fnameescape(fnamemodify(@%, ':p'.(@%[-1:]=~'[\\/]'?':h':'').repeat(':h',v:count1)))<CR>
  28. highlight default link DirvishSuffix SpecialKey
  29. highlight default link DirvishPathTail Directory
  30. highlight default link DirvishArg Todo
  31. if mapcheck('-', 'n') ==# '' && !hasmapto('<Plug>(dirvish_up)', 'n')
  32. nmap - <Plug>(dirvish_up)
  33. endif