dirvish.vim 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. if exists("b:did_ftplugin")
  2. finish
  3. endif
  4. let b:did_ftplugin = 1
  5. let s:nowait = (v:version > 703 ? '<nowait>' : '')
  6. let s:sep = exists('+shellslash') && !&shellslash ? '\' : '/'
  7. if !hasmapto('<Plug>(dirvish_quit)', 'n')
  8. execute 'nmap '.s:nowait.'<buffer> q <Plug>(dirvish_quit)'
  9. execute 'nmap '.s:nowait.'<buffer> gq <Plug>(dirvish_quit)'
  10. endif
  11. if !hasmapto('<Plug>(dirvish_arg)', 'n')
  12. execute 'nmap '.s:nowait.'<buffer> x <Plug>(dirvish_arg)'
  13. execute 'xmap '.s:nowait.'<buffer> x <Plug>(dirvish_arg)'
  14. endif
  15. if !hasmapto('<Plug>(dirvish_K)', 'n')
  16. execute 'nmap '.s:nowait.'<buffer> K <Plug>(dirvish_K)'
  17. execute 'xmap '.s:nowait.'<buffer> K <Plug>(dirvish_K)'
  18. endif
  19. if has('nvim') || has('patch-8.2.1978')
  20. let s:command_prefix = '<cmd>'
  21. let s:call_prefix = '<cmd>'
  22. let s:cmdsuf = ''
  23. else
  24. let s:command_prefix = ':<C-U>'
  25. let s:call_prefix = ':<C-U>.'
  26. let s:cmdsuf = ":echon ''<CR>"
  27. endif
  28. execute 'nnoremap '.s:nowait.'<buffer> ~ '.s:command_prefix.'Dirvish ~/<CR>'.s:cmdsuf
  29. execute 'nnoremap '.s:nowait.'<buffer> i '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:cmdsuf
  30. execute 'nnoremap '.s:nowait.'<buffer> <CR> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:cmdsuf
  31. execute 'nnoremap '.s:nowait.'<buffer> a '.s:call_prefix.'call dirvish#open("vsplit", 1)<CR>'.s:cmdsuf
  32. execute 'nnoremap '.s:nowait.'<buffer> o '.s:call_prefix.'call dirvish#open("split", 1)<CR>'.s:cmdsuf
  33. execute 'nnoremap '.s:nowait.'<buffer> p '.s:call_prefix.'call dirvish#open("p", 1)<CR>'.s:cmdsuf
  34. execute 'nnoremap '.s:nowait.'<buffer> <2-LeftMouse> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:cmdsuf
  35. execute 'nnoremap '.s:nowait.'<buffer><silent> dax :<C-U>arglocal<Bar>silent! argdelete *<Bar>echo "arglist: cleared"<Bar>Dirvish<CR>'
  36. execute 'nnoremap '.s:nowait.'<buffer><silent> <C-n> <C-\><C-n>j:call feedkeys("p")<CR>'
  37. execute 'nnoremap '.s:nowait.'<buffer><silent> <C-p> <C-\><C-n>k:call feedkeys("p")<CR>'
  38. if !has('nvim') && !has('patch-8.2.1978')
  39. let s:call_prefix = ':'
  40. endif
  41. execute 'xnoremap '.s:nowait.'<buffer> I '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:cmdsuf
  42. execute 'xnoremap '.s:nowait.'<buffer> <CR> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:cmdsuf
  43. execute 'xnoremap '.s:nowait.'<buffer> A '.s:call_prefix.'call dirvish#open("vsplit", 1)<CR>'.s:cmdsuf
  44. execute 'xnoremap '.s:nowait.'<buffer> O '.s:call_prefix.'call dirvish#open("split", 1)<CR>'.s:cmdsuf
  45. execute 'xnoremap '.s:nowait.'<buffer> P '.s:call_prefix.'call dirvish#open("p", 1)<CR>'.s:cmdsuf
  46. nnoremap <buffer><silent> R :<C-U><C-R>=v:count ? ':let g:dirvish_mode='.v:count.'<Bar>' : ''<CR>Dirvish<CR>
  47. nnoremap <buffer><silent> g? :help dirvish-mappings<CR>
  48. execute 'nnoremap <expr>'.s:nowait.'<buffer> . ":<C-u>".(v:count ? "Shdo".(v:count?"!":"")." {}" : ("! ".shellescape(empty(fnamemodify(getline("."),":.")) ? "." : fnamemodify(getline("."),":."), 1)))."<Home><C-Right>"'
  49. execute 'xnoremap <expr>'.s:nowait.'<buffer> . ":Shdo".(v:count?"!":" ")." {}<Left><Left><Left>"'
  50. execute 'nnoremap <expr>'.s:nowait.'<buffer> cd ":<C-u>".(v:count ? "cd" : "lcd")." %<Bar>pwd<CR>"'
  51. " Buffer-local / and ? mappings to skip the concealed path fragment.
  52. if s:sep == '\'
  53. nnoremap <buffer> / /\ze[^\/]*[\/]\=$<Home>
  54. nnoremap <buffer> ? ?\ze[^\/]*[\/]\=$<Home>
  55. else
  56. nnoremap <buffer> / /\ze[^/]*[/]\=$<Home>
  57. nnoremap <buffer> ? ?\ze[^/]*[/]\=$<Home>
  58. endif
  59. " Force autoload if `ft=dirvish`
  60. if !exists('*dirvish#open')|try|call dirvish#open()|catch|endtry|endif