question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

  • plugin version(SHA1):

    • silent! let g:plugs[‘defx.nvim’].commit = ‘d4bf081bc6bdf062097fddbbcf9c8fdf5b8fb101’
    • silent! let g:plugs[‘vim-tmux-navigator’].commit = ‘0cabb1ef01af0986b7bf6fb7acf631debdbbb470’
  • OS: Linux

  • neovim/Vim version: NVIM v0.5.0

  • :checkhealth or :CheckHealth result(neovim only):


health#defx#check
========================================================================
## defx.nvim
  - OK: has("python3") was successful
  - OK: Python 3.6.1+ was successful

health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: Release

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=^H
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $VTE_VERSION='6402'
  - INFO: $COLORTERM='truecolor'

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: wl-copy

## Python 2 provider (optional)
  - INFO: pyenv: Path: /home/francium/.pyenv/libexec/pyenv
  - INFO: pyenv: Root: /home/francium/.pyenv
  - WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
  - ERROR: Python provider error:
    - ADVICE:
      - provider/pythonx: Could not load Python 2:
          /usr/bin/python2 does not have the "neovim" module. :help |provider-python|
          /usr/bin/python2.7 does not have the "neovim" module. :help |provider-python|
          python2.6 not found in search path or not executable.
          /home/francium/.pyenv/shims/python is Python 3.9 and cannot provide Python 2.
  - INFO: Executable: Not found

## Python 3 provider (optional)
  - INFO: pyenv: Path: /home/francium/.pyenv/libexec/pyenv
  - INFO: pyenv: Root: /home/francium/.pyenv
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - WARNING: pyenv is not set up optimally.
    - ADVICE:
      - Create a virtualenv specifically for Nvim using pyenv, and set `g:python3_host_prog`.  This will avoid the need to install the pynvim module in each version/virtualenv.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python version: 3.9.6
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - OK: no $VIRTUAL_ENV

## Ruby provider (optional)
  - WARNING: `ruby` and `gem` must be in $PATH.
    - ADVICE:
      - Install Ruby and verify that `ruby` and `gem` commands work.

## Node.js provider (optional)
  - WARNING: `node` and `npm` (or `yarn`) must be in $PATH.
    - ADVICE:
      - Install Node.js and verify that `node` and `npm` (or `yarn`) commands work.

## Perl provider (optional)
  - ERROR: perl provider error:
    - ADVICE:
      - "Neovim::Ext" cpan module is not installed

health#treesitter#check
========================================================================
## Checking treesitter configuration
  - INFO: Runtime ABI version : 13

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
franciumcommented, Aug 13, 2021

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!

1reaction
Shougocommented, Aug 13, 2021
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong split and window positions · Issue #66 · Shougo/defx ...
iv) close the defx buffer with q , move to the right to the a.txt file ... :Defx from one window and press...
Read more >
Defx: file explorer plugin for Neovim - eed3si9n
I made <Space>-e to split Defx to the left. q closes it. j / k moves ... Using this I can go up...
Read more >
The collected mathematical papers of Arthur Cayley.
If you have questions about the collection, please contact Historical Mathematics Digital Collection Help at umhistmath-help@umich.edu. If you have concerns ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found