Shougo / defx.nvim

:file_folder: The dark powered file explorer implementation for neovim/Vim8
MIT License
1.17k stars 86 forks source link

Support for using c-h/j/k/l to move in and out of defx split #307

Closed francium closed 3 years ago

francium commented 3 years ago

Problems summary

I've got <c-h>, <c-j>, <c-k>, <c-l> mapped to move between splits instead of having to type <c-w> + h/j/k/l I've also got vim-tmux-navigator that allows seamless movement using those same mappings between vim and tmux splits.

I've only recently started looking at NERDTree alternatively. I'd like to give defx a try, but I'm seeing an issue with these set of mappings. With NERDTree these mappings were working fine and I could move between NERDTree, other vim splits and tmux splits seamlessly.

Expected

Use <c-h>, <c-j>, <c-k>, <c-l> to move between defx and vim splits

Environment Information

health#defx#check

defx.nvim

health#nvim#check

Configuration

Performance

Remote Plugins

terminal

health#provider#check

Clipboard (optional)

Python 2 provider (optional)

Python 3 provider (optional)

Python virtualenv

Ruby provider (optional)

Node.js provider (optional)

Perl provider (optional)

health#treesitter#check

Checking treesitter configuration

Provide a minimal init.vim/vimrc with less than 50 lines (Required!)

" Disabled because Tmux Vim Navigator mappings are used to handle movement
" nmap <C-J> <C-W><C-J>
" nmap <C-K> <C-W><C-K>
" nmap <C-L> <C-W><C-L>
" nmap <C-H> <C-W><C-H>

call plug#begin()

Plug 'https://github.com/christoomey/vim-tmux-navigator'

if has('nvim')
    Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
else
    Plug 'Shougo/defx.nvim'
    Plug 'roxma/nvim-yarp'
    Plug 'roxma/vim-hug-neovim-rpc'
endif

call plug#end()

" TMUX NAVIGATOR """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <C-H> :TmuxNavigateLeft<cr>
nnoremap <silent> <C-J> :TmuxNavigateDown<cr>
nnoremap <silent> <C-K> :TmuxNavigateUp<cr>
nnoremap <silent> <C-L> :TmuxNavigateRight<cr>
nnoremap <silent> <C-/> :TmuxNavigatePrevious<cr>

" DEFX """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <leader><tab> <cmd>Defx<cr>

call defx#custom#option('_', {
    \ 'winwidth': 30,
    \ 'split': 'vertical',
    \ 'direction': 'topleft',
    \ 'show_ignored_files': 0,
    \ 'buffer_name': 'defxplorer',
    \ 'toggle': 1,
    \ 'resume': 1
    \ })

autocmd FileType defx call s:defx_my_settings()
function! s:defx_my_settings() abort
    " Define mappings
    " ......... These are same as the ones in the doc example .........
endfunction

The reproduce ways from neovim/Vim starting (Required!)

  1. :sp to create a new split
  2. Use <c-j>, <c-k> to move between them
  3. <leader><tab> to open defx
  4. Use <c-h> to move to into defx split
  5. Note you now can't use <c-l> to move out of defx
francium commented 3 years ago

I just tried without vim-tmux-navigator and with just defx + these mappings:

nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
nmap <C-L> <C-W><C-L>
nmap <C-H> <C-W><C-H>

Same result, I can move between non-defx splits fine, and I can move into defx split from a non-defx split using one of these mappings. But once inside defx split, I can't use anything except <c-w>+h/j/k/l to move out.

Shougo commented 3 years ago

Really? Please wait.

Shougo commented 3 years ago
set runtimepath+=~/work/defx.nvim
set runtimepath+=~/work/nvim-yarp/
set runtimepath+=~/work/vim-hug-neovim-rpc/

augroup vimrc_defx
  autocmd!
  autocmd VimEnter * call Setup_Defx()
augroup END

function! Setup_Defx() abort
  call defx#custom#option('_', {
        \ 'winwidth': 30,
        \ 'split': 'vertical',
        \ 'direction': 'topleft',
        \ 'show_ignored_files': 0,
        \ 'buffer_name': 'defxplorer',
        \ 'columns': 'indent:filename',
        \ })
endfunction

nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
nmap <C-L> <C-W><C-L>
nmap <C-H> <C-W><C-H>

It works for me.

Shougo commented 3 years ago

I think you have not tested the minimal vimrc.

Shougo commented 3 years ago

And you should use nnoremap instead of nmap.

francium commented 3 years ago

@Shougo No I definitely tested my minimal vimrc, I commented out rest of my config, and only had those lines of config I've included above.

But let me try with just what you've pasted, I'll double check if you say it's working for you. Thanks for the quick reply also!

francium commented 3 years ago

Just tested your config. You're correct, it does work. So something I've done is incorrect. I'll narrow down the issue myself. Thank you for your help!

timtraversy commented 2 years ago

I also broke vim-tmux-navigator when I copied the default defx configuration. In my case, it was because the default config maps <C-L> to redraw, which was overriding the vim-tmux-navigator mapping of <C-L> to go right.

Fixed by changing that mapping in my defx config.