1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 02:30:05 +08:00
SpaceVim/config/plugins/nerdtree.vim
2017-12-01 16:17:32 +08:00

42 lines
1.3 KiB
VimL

let s:VCOP = SpaceVim#api#import('vim#compatible')
let g:NERDTreeWinPos=get(g:,'NERDTreeWinPos','right')
let g:NERDTreeWinSize=get(g:,'NERDTreeWinSize',31)
let g:NERDTreeChDirMode=get(g:,'NERDTreeChDirMode',1)
augroup nerdtree_zvim
autocmd!
autocmd bufenter *
\ if (winnr('$') == 1 && exists('b:NERDTree')
\ && b:NERDTree.isTabTree())
\| q
\| endif
autocmd FileType nerdtree call s:nerdtreeinit()
augroup END
function! s:nerdtreeinit() abort
nnoremap <silent><buffer> yY :<C-u>call <SID>copy_to_system_clipboard()<CR>
nnoremap <silent><buffer> P :<C-u>call <SID>paste_to_file_manager()<CR>
endfunction
function! s:paste_to_file_manager() abort
let path = g:NERDTreeFileNode.GetSelected().path.str()
if !isdirectory(path)
let path = fnamemodify(path, ':p:h')
endif
let old_wd = getcwd()
if old_wd == path
call s:VCOP.systemlist(['xclip-pastefile'])
else
noautocmd exe 'cd' fnameescape(path)
call s:VCOP.systemlist(['xclip-pastefile'])
noautocmd exe 'cd' fnameescape(old_wd)
endif
endfunction
function! s:copy_to_system_clipboard() abort
let filename = g:NERDTreeFileNode.GetSelected().path.str()
call s:VCOP.systemlist(['xclip-copyfile', filename])
echo 'Yanked:' . (type(filename) == 3 ? len(filename) : 1 ) . ( isdirectory(filename) ? 'directory' : 'file' )
endfunction