Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim wildmenu: move into subdirectory with a different key than <down>

Tags:

vim

This has been bothering me for quite a long time. I like to use wildmenu for browsing directories in command mode. The problem is that for entering into subdirectory I need to use <down> key which is always out of reach. I tried to make some mapping to overcome this issue but without success. For instance:

cnoremap <C-j> <DOWN>

But if I press <C-j> when I want to enter a subdirectory in wildmenu, the menu disappears and ^I occurs at the end of the command line. Any idea how to solve this?

like image 482
clime Avatar asked Jan 14 '23 05:01

clime


1 Answers

I can reproduce this. It looks like command-line mappings (same with <Tab>, not just <Down>) aren't interpreted in wildmenu mode, and instead exit it and insert the 'wildchar' literally. You can report this to the vim_dev mailing list. I think additionally a wildmenuvisible() function analog to the pumvisible() would be needed, so that mappings could behave differently depending on whether the wildmenu is currently active.

You can work around the issue with feedkeys(), though:

function! EnterSubdir()
    call feedkeys("\<Down>", 't')
    return ''
endfunction
cnoremap <expr> <C-j> EnterSubdir()
like image 151
Ingo Karkat Avatar answered Feb 06 '23 22:02

Ingo Karkat