From dc3c23fe3e77e3b73b6fe1288b39e0a620b7b90d Mon Sep 17 00:00:00 2001 From: alanding <395577197@qq.com> Date: Wed, 3 Apr 2019 11:07:27 +0800 Subject: [PATCH] enhance defx keymap l --- config/plugins/defx.vim | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/config/plugins/defx.vim b/config/plugins/defx.vim index 123afa022..aeae10bca 100644 --- a/config/plugins/defx.vim +++ b/config/plugins/defx.vim @@ -95,12 +95,8 @@ function! s:defx_init() \ defx#do_action('paste') nnoremap h defx#do_action('call', 'DefxSmartH') nnoremap defx#do_action('call', 'DefxSmartH') - nnoremap l - \ defx#is_directory() ? - \ defx#do_action('open_tree') . 'j' : defx#do_action('drop') - nnoremap - \ defx#is_directory() ? - \ defx#do_action('open_tree') . 'j' : defx#do_action('open') + nnoremap l defx#do_action('call', 'DefxSmartL') + nnoremap defx#do_action('call', 'DefxSmartL') nnoremap \ defx#is_directory() ? \ defx#do_action('open_directory') : defx#do_action('drop') @@ -138,6 +134,32 @@ function! s:defx_init() \ defx#do_action('change_vim_cwd') endf +function! DefxSmartL(_) + if defx#is_directory() + call defx#call_action('open_tree') + normal! j + else + let filepath = defx#get_candidate()['action__path'] + if tabpagewinnr(tabpagenr(), '$') >= 3 + if has('nvim') + let input = input({ + \ 'prompt' : 'ChooseWin No.: ', + \ 'cancelreturn': 0, + \ }) + if input == 0 | return | endif + else + let input = input('ChooseWin No.: ') + endif + if input == winnr() | return | endif + exec ': ' . input . 'wincmd w' + exec ':e' . filepath + else + exec 'wincmd w' + exec ':e' . filepath + endif + endif +endfunction + function! DefxSmartH(_) " candidate is opend tree? if defx#is_opened_tree()