2021-09-12 23:06:37 +08:00
|
|
|
scriptencoding utf-8
|
2017-12-01 16:17:32 +08:00
|
|
|
let s:VCOP = SpaceVim#api#import('vim#compatible')
|
2021-09-12 23:06:37 +08:00
|
|
|
let s:FILE = SpaceVim#api#import('file')
|
2019-07-11 18:26:29 +08:00
|
|
|
if get(g:, 'spacevim_filetree_direction', 'right') ==# 'right'
|
2019-03-14 00:03:35 +08:00
|
|
|
let g:NERDTreeWinPos = 'rightbelow'
|
|
|
|
else
|
2019-03-20 20:52:37 +08:00
|
|
|
let g:NERDTreeWinPos = 'left'
|
2019-03-14 00:03:35 +08:00
|
|
|
endif
|
2021-09-19 17:32:31 +08:00
|
|
|
let g:NERDTreeWinSize=get(g:,'NERDTreeWinSize', get(g:, 'spacevim_sidebar_width', 35))
|
2017-12-01 16:17:32 +08:00
|
|
|
let g:NERDTreeChDirMode=get(g:,'NERDTreeChDirMode',1)
|
2019-10-05 22:31:49 +08:00
|
|
|
let g:NERDTreeShowHidden = get(g:, '_spacevim_filetree_show_hidden_files', 0)
|
2021-09-19 17:32:31 +08:00
|
|
|
let g:NERDTreeDirArrowExpandable = get(g:, 'NERDTreeDirArrowExpandable', get(g:, '_spacevim_filetree_closed_icon', ''))
|
|
|
|
let g:NERDTreeDirArrowCollapsible = get(g:, 'NERDTreeDirArrowCollapsible', get(g:, '_spacevim_filetree_opened_icon', ''))
|
|
|
|
let g:NERDTreeMinimalUI=1
|
2017-12-01 16:17:32 +08:00
|
|
|
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>
|
2021-09-12 23:06:37 +08:00
|
|
|
nnoremap <silent><buffer> h :<C-u>call <SID>nerdtree_h()<CR>
|
2021-09-25 00:38:39 +08:00
|
|
|
nnoremap <silent><buffer> d :<C-u>call NERDTreeDeleteNode()<CR>
|
2021-09-12 23:06:37 +08:00
|
|
|
nnoremap <silent><buffer> l :<C-u>call <SID>nerdtree_l()<CR>
|
2021-09-22 22:54:02 +08:00
|
|
|
nnoremap <silent><buffer> <Left> :<C-u>call <SID>nerdtree_h()<CR>
|
|
|
|
nnoremap <silent><buffer> <Right> :<C-u>call <SID>nerdtree_l()<CR>
|
2021-09-20 22:33:28 +08:00
|
|
|
nnoremap <silent><buffer> N :<C-u>call NERDTreeAddNode()<CR>
|
2021-09-20 22:45:49 +08:00
|
|
|
nnoremap <silent><buffer> . :<C-u>call <SID>nerdtree_dot()<CR>
|
2024-06-09 18:47:12 +08:00
|
|
|
nnoremap <silent><buffer> <C-h> :<C-u>NERDTreeCWD<CR>
|
2021-09-21 23:46:10 +08:00
|
|
|
nnoremap <silent><buffer> <CR> :<C-u>call <SID>nerdtree_enter()<CR>
|
|
|
|
" nnoremap <silent><buffer> <CR> :<C-u>silent! exe 'NERDTree' g:NERDTreeFileNode.GetSelected().path.str()<CR>
|
2021-09-25 00:41:22 +08:00
|
|
|
nnoremap <silent><buffer> <Home> :call cursor(2, 1)<cr>
|
|
|
|
nnoremap <silent><buffer> <End> :call cursor(line('$'), 1)<cr>
|
2023-04-15 18:26:13 +08:00
|
|
|
try
|
|
|
|
doautocmd User NerdTreeInit
|
|
|
|
catch
|
|
|
|
endtry
|
2017-12-01 16:17:32 +08:00
|
|
|
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
|
2021-09-12 23:06:37 +08:00
|
|
|
|
|
|
|
function! s:nerdtree_h() abort
|
2021-09-25 01:12:26 +08:00
|
|
|
if g:NERDTree.ForCurrentTab().getRoot().path.str()
|
|
|
|
\ ==# g:NERDTreeFileNode.GetSelected().path.getParent().str()
|
|
|
|
silent! exe 'NERDTree' g:NERDTreeFileNode.GetSelected().path.getParent().getParent().str()
|
|
|
|
else
|
|
|
|
call g:NERDTreeKeyMap.Invoke('p')
|
|
|
|
call g:NERDTreeKeyMap.Invoke('o')
|
|
|
|
endif
|
2021-09-12 23:06:37 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:nerdtree_l() abort
|
|
|
|
let path = g:NERDTreeFileNode.GetSelected().path.str()
|
|
|
|
if isdirectory(path)
|
|
|
|
if matchstr(getline('.'), 'S') ==# g:NERDTreeDirArrowCollapsible
|
|
|
|
normal! gj
|
|
|
|
else
|
|
|
|
call g:NERDTreeKeyMap.Invoke('o')
|
|
|
|
normal! gj
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call g:NERDTreeKeyMap.Invoke('o')
|
|
|
|
endif
|
|
|
|
endfunction
|
2021-09-20 22:45:49 +08:00
|
|
|
|
|
|
|
function! s:nerdtree_dot() abort
|
|
|
|
call g:NERDTreeKeyMap.Invoke('I')
|
|
|
|
endfunction
|
2021-09-21 23:46:10 +08:00
|
|
|
|
|
|
|
function! s:nerdtree_enter() abort
|
2024-06-09 18:22:17 +08:00
|
|
|
let node = g:NERDTreeFileNode.GetSelected()
|
|
|
|
if has_key(node, 'path')
|
|
|
|
let path = node.path.str()
|
|
|
|
if isdirectory(path)
|
|
|
|
silent! exe 'NERDTree' g:NERDTreeFileNode.GetSelected().path.str()
|
|
|
|
else
|
|
|
|
call g:NERDTreeKeyMap.Invoke('o')
|
|
|
|
endif
|
2021-09-21 23:46:10 +08:00
|
|
|
endif
|
|
|
|
endfunction
|