Vim wildmenu: go to a subdirectory with a different key than <down>
This bothered me for a long time. I like to use wildmenu to browse directories in command mode. The problem is that to enter a subdirectory, I need to use a key <down>
that is always out of reach. I tried to do some mapping to solve this problem, with no success. For example:
cnoremap <C-j> <DOWN>
But if I click <C-j>
when I want to enter a subdirectory in wildmenu, the menu disappears and ^I
happens at the end of the command line. Any idea how to solve this?
source to share
I can reproduce this. It looks like command line collations (same with <Tab>
, not only <Down>
) are not interpreted in wildmenu mode, but instead exited and pasted 'wildchar'
literally. You can report this to the vim_dev mailing list . I think that a wildmenuvisible()
similar function is additionally needed pumvisible()
, so that the mappings can behave differently depending on whether wildmenu is active.
You can work around the problem with feedkeys()
, though:
function! EnterSubdir()
call feedkeys("\<Down>", 't')
return ''
endfunction
cnoremap <expr> <C-j> EnterSubdir()
source to share
Christian Braband came up with a solution on vim_dev : in order for your original display to work, you need to set 'wildcharm'
to the same value 'wildchar'
:
:let &wildcharm = &wildchar
:cnoremap <C-j> <DOWN>
source to share