9

One thing that really bothers me in vim (probably the only thing), is the wildmenu.

In neovim, the wildmenu is vertical and looks as following:

enter image description here

However, in vim, it is horizontal and looks like this:

enter image description here

Is it possible to get the vertical wildmenu in vim?

If possible, without a plugin, but if there is no other way then I don't mind.

7
  • The only one-entry-per-line command-line completion I'm aware of is for a very specific situation: when using :tag and you press Ctrl-D but only if you've done :set wop=tagfile. Yeah, extremely limited.
    – B Layer
    Jun 14, 2021 at 10:12
  • 1
    Kind of a shame since we know Vim can do that kind of display...autocomplete of any kind in the buffer does it. Sounds like a worthy feature request. (Assuming I'm not missing something already there.) Welcome to Vi&Vim SE, BTW.
    – B Layer
    Jun 14, 2021 at 10:20
  • 1
    @BLayer I have set wildoptions="pum,tagfile" enabled, but i still get the horizontal menu
    – Lea Hubert
    Jun 14, 2021 at 10:32
  • set wildoptions="pum" this is a neovim only addition. I don't think vim currently allows to use a vertical popup menu for the wildmenu. Jun 14, 2021 at 12:15
  • Actually, you've found a bit of a Vim issue. I believe the :set that you ran should emit an error message because it is rejecting the value...:set wop? shows no right-hand-side value. Now try it without the double quotes, :set wop=pum,tagfile and you'll get an error. But anyways...if you want to see the completion format I mentioned in my first comment you'll have to type it just like I show.
    – B Layer
    Jun 14, 2021 at 12:33

4 Answers 4

3

It's not available in Vim. However, there is a fork called Vim-CLPUM. You need its clpum branch, which is 2 years behind Vim's master at the moment. If you really like this feature, maybe you could help h-east with testing it or in some other way.

4
  • 1
    for now, i will just keep using neovim ;) *sigh... I want to stay native to vim, but there a some little things like this that i can't stand about vim..
    – Lea Hubert
    Jun 15, 2021 at 9:04
  • Wow...what are the odds that there's a branch (even a hopelessly outdated one) that does exactly what they want. How the heck did you know about it? I'm impressed. :)
    – B Layer
    Jun 16, 2021 at 19:20
  • @BLayer, I don't remember, probably saw the fork being mentioned in Vim's GitHub issue or somewhere else accidentally.
    – xaizek
    Jun 16, 2021 at 20:50
  • Well, +1 regardless.
    – B Layer
    Jun 16, 2021 at 20:52
8

Patch 8.2.4325 added the vertical wildmenu support to Vim.

2

Not exactly what OP asked but... maybe someone will find this useful.

There are countless plugins (commonly referred as "pickers") that allow user to pick an item from (vertical) popup menu and to execute some arbitrary command afterwards (vim-clap, nvim-telescope, you name it). Probably many of us also tried to create "fast buffer switch" or "colorscheme chooser" that works without even entering cmdline. Now with Vim8 +popupwin it's easy!

The main disappointment is that (callback) lambdas are really awkward to re-use: imagine we have a dozen of individual "pickers" each of which calls a generic Pick() function which in turn calls popup_menu(). Now every "picker" wants to have specific callback lambda but every lambda should also have access to all locals in Pick() too! Luckily, we can work around it using good old "substitute-eval-submatch" trick.

So the code for our generic Pick() function is

" Pick({name} [, {items} [, {cmd}]])
" pick parameter and execute {cmd}
function! Pick(...) abort
    let l:name = a:1
    let l:items = a:0 > 1 ? a:2 : getcompletion(l:name..' ', 'cmdline')
    let l:cmd = a:0 > 2 ? a:3 : '%{name} %{items[result - 1]}'
    call popup_menu(l:items, #{title: printf('[%s]', l:name), maxheight: &pumheight ?
        \ &pumheight : &lines / 2, minwidth: &pumwidth, callback: {id, result ->
        \ (result < 1 || result > len(items)) ? v:null :
        \ execute(substitute(l:cmd, '%{\([^}]\+\)}', '\=eval(submatch(1))', 'g'), '')}})
endfunction

So the third (optional) parameter is a String to evaluate and execute in the context of Pick()'s internal lambda. And inside our "special" %{...} expression we can actually access all those local variables! That allows for super-easy writing of menu callbacks.

" Choosing :colorscheme is trivial
nnoremap <silent><plug>colorscheme <cmd>call Pick('colorscheme')<CR>

" Choosing from :scriptnames using custom items and cmd
nnoremap <silent><plug>scriptnames <cmd>call Pick('scriptnames',
    \ map(split(execute('scriptnames'), "\n"), 'v:val[1:]'), '%{result}%{name}')<CR>

" Choosing buffer is a bit verbose as we have to prepare buffers list
nnoremap <silent><plug>buffers <cmd>call Pick('buffer', map(getbufinfo({'buflisted': 1}),
    \ {_, v -> printf('%2d %s', v.bufnr, empty(v.name) ? gettext('[No Name]') :
    \ fnamemodify(v.name, ':t'))}), '%{name} %{split(items[result - 1])[0]}')<CR>

And all others like "args", "find", "history", "marks", "oldfiles", "registers", "windows" and even "picker of pickers". The code is in my vimfiles repo. This gives us roughly a half of functionality of those plugin monsters such as nvim-telescope with only a few lines of "poor old" VimScript.

12
  • 2
    cool use of popups Oct 7, 2021 at 15:30
  • Slightly more judicious use of continuation lines might make this easier to read.
    – D. Ben Knoble
    Oct 7, 2021 at 23:58
  • 1
    @D.BenKnoble Lambdas and mappings are always hard to fit properly in VimScript. I admit my technique is far from good.
    – Matt
    Oct 8, 2021 at 7:13
  • @ChristianBrabandt Are there plans for a vertical wildmenu in Vim? I find all the options given not pleasing. The vertical menu is the only thing so far I find better in Neovim.
    – neolith
    Feb 1 at 5:52
  • @neolith I am not aware of this. You may open a wishlist issue for this for Vim. Not sure this will make it implemented, since we have popup menus, so you might be prepared for some discussions about it Feb 1 at 9:07
2

Thank you for posting this question. The same thing is bothering me as well.

At first, I thought there was a new plugin - wilder, but it appears (to me) that the vertical-nature is not given.

I did not try to install the python dependencies.

Nonetheless, I am recommending to try the following pair of options:

set nowildmenu
set wildmode=list:full

This is the best aid and almost mimics the vertical menu when completing the cmdline.


update on 03. Juli 2022, because vim 9 was released.

The changelog did not prompt me with this feature, but the following thread: How to get vertical wild menu using wildoptions=pum on Vim 9.0.

After a short search, the following PR (attribution!), even though it was not merged, initiated the support for this menu: https://github.com/vim/vim/pull/9707.

You need to activate an alternative behaviour by

set wildmenu

Then configure it like so:

set wildoptions=pum

Have fun!

2
  • 1
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Oct 7, 2021 at 1:29
  • I was just revisiting my first answer; I am curious about your feedback. Sincerely
    – Tomes
    Dec 14, 2021 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.