如何有效地使用 Vim: 通配菜单

我有点搞不懂 Vim 的菜单是怎么用的。我有 set wildmenuset wildmode=list:longest,full,但我一辈子都不明白如何调用和使用完成特性。

这个特性有用吗?为什么,怎么做到的?这到底是怎么完成的?换句话说,是什么决定了完成列表的内容?

任何提示和示例用法将不胜感激。

75803 次浏览

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.

: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.

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>

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.

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