78

I'm a bit confused about the use of Vim's menus. I have set wildmenu and set wildmode=list:longest,full but I don't understand for the life of me how to invoke and use the completion feature.

Is this feature useful? Why and how? What kind of completion does this do exactly? In other words, what determines the completion list content?

Any tips and example usages would be appreciated.

1
  • I have set wildmenu. And find it quite useful. I don't have to tab a lot if the item i wan't doesn't show on the hint bar. Commented Mar 1, 2012 at 6:14

6 Answers 6

88

wildmenu and wildmode are used for command line completion. The simplest way to try it would be with :color <Tab>: the command line is "expanded" vertically with a list of all the colorschemes available on your machine displayed in columns and an horizontal strip that you can navigate with <Tab> (forward) and <S-Tab> (backward).

The behaviour of command line completion and wildmenu are dependant on wildmode.

See :help wildmode and :help wildmenu for more details.

3
  • 3
    So what I'm getting is it's autocompletion for vim commands! Which makes more sense. Is it able to go beyond that? Perhaps syntax detection to autocomplete function/variable names within, say, .cpp files?
    – skippr
    Commented Mar 5, 2012 at 1:20
  • 4
    No the wildmode/wildmenu combo can't do anything beyond command line completion. Vim has another mechanism for code completion called "omni-completion". Read :help omni-completion for more info.
    – romainl
    Commented Mar 5, 2012 at 6:05
  • this is a good point. thanks. code complete is another thing. if it helps. ALE or Coc (conquerer of code) uses another form of popup menus; which is a completely different thing. Commented Feb 26, 2023 at 10:38
72

Probably the most comfortable option, at least for me is:

set wildmenu
set wildmode=longest:full,full

That means that on first <Tab> it will complete to the longest common string and will invoke wildmenu (a horizontal and unobtrusive little menu). On next <Tab> it will complete the first alternative and it will start to cycle through the rest. You can go back and forth with <Tab> and <S-Tab> respectively.

An awesome example on how wildmenu is very useful, is to complete buffers, use the config I posted and then try:

:b<Tab>

4
  • Can you explain how does it work? The help page doesn't say anything about the :.
    – saga
    Commented Jun 8, 2017 at 18:16
  • 1
    It's described in the vim help: vimdoc.sourceforge.net/htmldoc/options.html#'wildmode' (but you have to look into wildmode, and not wildmenu) Commented Jun 11, 2017 at 16:29
  • 2
    Do you mean :b <Tab> rather than :b<Tab> ?
    – tonywoode
    Commented Sep 20, 2020 at 8:37
  • 2
    Yeahhhhh! Thanks a lot. It took me a long time to find this answer, because I didn't know how to describe the desired behaviour to Google. Cool! Commented Mar 28, 2021 at 19:17
25

My favorite is

set wildmenu
set wildmode=longest:list,full

First tab will complete to longest string and show the the match list, then second tab will complete to first full match and open the wildmenu.

0
8

:set wildmode=list:longest allows you to expand the wildmenu.

:set wildmenu allows you to use <Left> or <Right> to navigate through the completion lists.

4
  • 1
    Is there a way so that if you hit tab, you could scroll through the completion lists?
    – hlin117
    Commented Feb 18, 2016 at 17:03
  • 2
    just :set wildmenu=list:full instead. Commented Feb 18, 2016 at 17:33
  • Linh: This is so close to what I want; I might not have been clear with my previous question. Is there a way so you could scroll through the expanded wildmenu? This functionality's similar to zsh: i.sstatic.net/GvC4A.png
    – hlin117
    Commented Feb 18, 2016 at 21:51
  • @hlin117, unfortunately I haven't seen that feature implemented in Vim. If it's only for command, Unite has an interface for it (think "Goto Anything")... Commented Feb 18, 2016 at 22:44
1

You may want to config wildoptions. Please refer to this answer on Vi and Vim Stack Exchange.

0

I use set wildmenu=full:lastused (not documented in help) which follows recent buffer history (according to :ls t order). Something I appreciate the most.

The navigation principle is the same as set wildmenu=full similar to =longest:full,full but with the advantage of completing the first full match immediately (whereas longest:full,full first only completes a common part and you still have to press Tab again to select first item).

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