[vim/vim] Command line mode mapping to <down> not working with wildmenu. (#6045)

42 views
Skip to first unread message

Daniel Steinberg

unread,
May 5, 2020, 5:32:50 PM5/5/20
to vim/vim, Subscribed

Describe the bug

The documentation for wildmenumode() provides an example to make <c-j> work like <down> in wildmode:

:cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"

After creating that mapping, using <c-j> when the wildmenu is shown results in ^I being appended to the command line command.

The following mapping—intended to highlight the issue as opposed to be useful on its own—also encounters the problem.

:cnoremap j <Down>

To Reproduce

Detailed steps to reproduce the behavior:

  1. Run vim --clean
  2. Create mapping: :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
  3. Type :e / followed by <tab> to bring up the wildmenu for the root directory.
  4. Press <C-j>, which should "work like <down>".
  5. ^I is appended to the command (twice), as opposed to having the same behavior as pressing <down>.

Expected behavior

I was expecting a move into the selected subdirectory, which is what happens when pressing <down>.

Environment (please complete the following information):

  • Vim version: 8.2.700
  • OS: Ubuntu 19.10
  • Terminal: GNOME Terminal 3.34.2


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
May 5, 2020, 6:02:26 PM5/5/20
to vim/vim, Subscribed

Possible duplicate of: #4954

For a workaround, make sure that 'wildcharm' has the same value as 'wildchar' (whose default is <Tab>/9):

vim -Nu NONE +'set wildmenu wildcharm=9' +'cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"'
                            ^^^^^^^^^^^

lacygoill

unread,
May 5, 2020, 6:13:58 PM5/5/20
to vim/vim, Subscribed

Or use feedkeys() with the t flag:

vim -Nu NONE +'set wildmenu' +'cnoremap <expr> <C-j> wildmenumode() ? feedkeys("\<down>\<tab>", "t")[-1] : "\<c-j>"'
                                                                                                 ^

See also:

Daniel Steinberg

unread,
May 5, 2020, 6:16:09 PM5/5/20
to vim/vim, Subscribed

Thanks @lacygoill.

(the example mapping in the documentation for wildmenumode() maps <c-j> to <down><tab>, but it seems that <down> alone works as expected, and the extra <tab> causes selection of the second item).

Daniel Steinberg

unread,
May 5, 2020, 6:16:13 PM5/5/20
to vim/vim, Subscribed

Closed #6045.

lacygoill

unread,
Dec 26, 2020, 8:38:40 AM12/26/20
to vim/vim, Subscribed

Fixed by 8.2.2221.

Reply all
Reply to author
Forward
0 new messages