From c2228a6db9cc89ef5a01a08e4cba511192e42604 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 18 Apr 2019 22:09:28 +0800 Subject: [PATCH] Fix SPC j d/D key binding (#2753) --- autoload/SpaceVim/layers/core.vim | 44 ++++++++++++++++++++++++------- config/plugins/defx.vim | 4 +-- config/plugins/vimfiler.vim | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/autoload/SpaceVim/layers/core.vim b/autoload/SpaceVim/layers/core.vim index c183ec147..1892c04ce 100644 --- a/autoload/SpaceVim/layers/core.vim +++ b/autoload/SpaceVim/layers/core.vim @@ -11,7 +11,7 @@ let s:SYS = SpaceVim#api#import('system') function! SpaceVim#layers#core#plugins() abort let plugins = [] if g:spacevim_filemanager ==# 'nerdtree' - call add(plugins, ['scrooloose/nerdtree', { 'on_cmd' : 'NERDTreeToggle', + call add(plugins, ['scrooloose/nerdtree', { 'merged' : 0, \ 'loadconf' : 1}]) elseif g:spacevim_filemanager ==# 'vimfiler' call add(plugins, ['Shougo/vimfiler.vim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1, 'on_cmd' : ['VimFiler', 'VimFilerBufferDir']}]) @@ -100,14 +100,12 @@ function! SpaceVim#layers#core#config() abort call SpaceVim#mapping#space#def('nnoremap', ['j', 'f'], '', 'jump forward', 0) " file tree key bindings - if g:spacevim_filemanager ==# 'vimfiler' - call SpaceVim#mapping#space#def('nnoremap', ['j', 'd'], 'VimFiler -no-split', 'Explore current directory', 1) - call SpaceVim#mapping#space#def('nnoremap', ['j', 'D'], 'VimFiler', 'Explore current directory (other window)', 1) - elseif g:spacevim_filemanager ==# 'nerdtree' - elseif g:spacevim_filemanager ==# 'defx' - call SpaceVim#mapping#space#def('nnoremap', ['j', 'd'], 'let g:_spacevim_autoclose_defx = 0 | Defx -split=no | let g:_spacevim_autoclose_defx = 1', 'Explore current directory', 1) - call SpaceVim#mapping#space#def('nnoremap', ['j', 'D'], 'Defx', 'Explore current directory (other window)', 1) - endif + call SpaceVim#mapping#space#def('nnoremap', ['j', 'd'], 'call call(' + \ . string(s:_function('s:explore_current_dir')) . ', [0])', + \ 'Explore current directory', 1) + call SpaceVim#mapping#space#def('nnoremap', ['j', 'D'], 'call call(' + \ . string(s:_function('s:explore_current_dir')) . ', [1])', + \ 'Explore current directory(other windows)', 1) call SpaceVim#mapping#space#def('nmap', ['j', 'j'], '(easymotion-overwin-f)', 'jump to a character', 0) call SpaceVim#mapping#space#def('nmap', ['j', 'J'], '(easymotion-overwin-f2)', 'jump to a suite of two characters', 0) @@ -663,3 +661,31 @@ endfunction function! s:restart_neovim_qt() abort call system('taskkill /f /t /im nvim.exe') endfunction + + +let g:_spacevim_autoclose_filetree = 1 +function! s:explore_current_dir(cur) abort + if g:spacevim_filemanager ==# 'vimfiler' + if !a:cur + let g:_spacevim_autoclose_filetree = 0 + VimFilerCurrentDir -no-split -no-toggle + let g:_spacevim_autoclose_filetree = 1 + else + VimFilerCurrentDir -no-toggle + endif + elseif g:spacevim_filemanager ==# 'nerdtree' + if !a:cur + exe 'e ' . getcwd() + else + NERDTreeCWD + endif + elseif g:spacevim_filemanager ==# 'defx' + if !a:cur + let g:_spacevim_autoclose_filetree = 0 + Defx -no-toggle -no-resume -split=no `getcwd()` + let g:_spacevim_autoclose_filetree = 1 + else + Defx -no-toggle + endif + endif +endfunction diff --git a/config/plugins/defx.vim b/config/plugins/defx.vim index 10faa9790..14365751a 100644 --- a/config/plugins/defx.vim +++ b/config/plugins/defx.vim @@ -34,14 +34,12 @@ call defx#custom#column('filename', { \ 'opened_icon': '', \ }) -let g:_spacevim_autoclose_defx = 1 - augroup vfinit au! autocmd FileType defx call s:defx_init() " auto close last defx windows autocmd BufEnter * nested if - \ (!has('vim_starting') && winnr('$') == 1 && g:_spacevim_autoclose_defx + \ (!has('vim_starting') && winnr('$') == 1 && g:_spacevim_autoclose_filetree \ && &filetype ==# 'defx') | \ call s:close_last_vimfiler_windows() | endif augroup END diff --git a/config/plugins/vimfiler.vim b/config/plugins/vimfiler.vim index f8b3a505e..e2bf10db8 100644 --- a/config/plugins/vimfiler.vim +++ b/config/plugins/vimfiler.vim @@ -68,7 +68,7 @@ call vimfiler#custom#profile('default', 'context', { augroup vfinit au! autocmd FileType vimfiler call s:vimfilerinit() - autocmd BufEnter * nested if (!has('vim_starting') && winnr('$') == 1 && &filetype ==# 'vimfiler') | + autocmd BufEnter * nested if (!has('vim_starting') && winnr('$') == 1 && &filetype ==# 'vimfiler' && g:_spacevim_autoclose_filetree) | \ call s:close_last_vimfiler_windows() | endif augroup END