11

I'm wanting to learn Vim, but think it's probably too daunting. I imagine learning enough to become powerful with it, then forgetting 99% after I'm on a computerless project for a while. I know just enough right now to open a file and get stuck, or make a huge mess and exit. If there is an autocomplete feature for commands, I might be able to remember more easily.

QUESTION: Is there a version of Vim (or a plugin) that features an AutoComplete for Command Mode for those who can't remember a lot?

...and to avoid confusion, I don't mean an auto completion for a programming language functions and methods, but an autocomplete for Vim's command mode itself, with perhaps a command description too.

6
  • 3
    Maybe keep this up in a second monitor? Since most of the commands are one character long, I don't see auto-completion helping you very much.
    – Tumbler41
    Commented Feb 14, 2017 at 23:46
  • 1
    Not sure this is exactly what you want, but there's this plugin: github.com/lifepillar/vim-cheat40 Once installed, you can access a cheat sheet by pressing <leader>?. You can also define your own cheat sheet, it's explained on the readme page. Commented Feb 15, 2017 at 1:06
  • 4
    Vim's command mode does have autocomplete (and has had it for a long time). :foo<Tab> will cycle through matching commands. You can even do :<Tab>.
    – muru
    Commented Feb 15, 2017 at 1:43
  • 1
    @user12711 If you type :echo mapleader, it should output what is your current leader key. If it gives an error (because the variable mapleader wasn't defined), then it probably means that your leader key is a a backslash (it's the default value). You can change its value in your vimrc, by writing let mapleader="your_key". For example, let mapleader = "\<Space>". See :h mapleader for more info. Commented Feb 15, 2017 at 14:21
  • 1
    @user12711 So if your leader key is a comma for example, then pressing <Leader>? means pressing ,?. If it's a space, then it means pressing a space then ?. And so on. Commented Feb 15, 2017 at 15:45

4 Answers 4

24

I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opinion is to learn the basics of the editor and then learn more and more commands.

Anyway Vim has a built-in auto completion feature for the command line it is controlled with the wildmenu and wildmode options.

The first step is to create your vimrc file if it doesn't exists yet and to add the following line:

set wildmenu

See the doc :h 'wildmenu':

When 'wildmenu' is on, command-line completion operates in an enhanced
mode.  On pressing 'wildchar' (usually <Tab>) to invoke completion,
the possible matches are shown just above the command line, with the
first match highlighted (overwriting the status line, if there is
one).  Keys that show the previous/next match, such as <Tab> or
CTRL-P/CTRL-N, cause the highlight to move to the appropriate match.

Then add your wildmode configuration. Personally I used the following line but you might want to modify it to fit your needs:

set wildmode=longest,list,full

To see which options are the most relevant for you have a look at the doc :h 'wildmode':

Completion mode that is used for the character specified with
'wildchar'.  It is a comma separated list of up to four parts.  Each
part specifies what to do for each consecutive use of 'wildchar'.  The
first part specifies the behavior for the first use of 'wildchar',
The second part for the second use, etc.
These are the possible values for each part:
""              Complete only the first match.
"full"          Complete the next full match.  After the last match,
                the original string is used and then the first match
                again.
"longest"       Complete till longest common string.  If this doesn't
                result in a longer string, use the next part.
"longest:full"  Like "longest", but also start 'wildmenu' if it is
                enabled.
"list"          When more than one match, list all matches.
"list:full"     When more than one match, list all matches and
                complete first match.
"list:longest"  When more than one match, list all matches and
                complete till longest common string.
When there is only a single match, it is fully completed in all cases.
3
  • Is there something for shell command execution in Vim? Commented Jun 20, 2020 at 4:22
  • @VishalDalwadi I am not sure I understand what you are asking. If you have a question please ask a new one on this site, this will allow you to give more details about what you are looking for.
    – statox
    Commented Jun 20, 2020 at 10:48
  • Ok I will. Thanks! Commented Jun 20, 2020 at 15:11
5

Besides built-in wildmenu, you can try wilder.nvim plugin. It provides more features, such as showing suggestions as you type.

demo

3

Besides wildmode, wildmenu is also controlled by wildoptions. You can see the doc by :h 'wildoptions'.

I like pum, because it gives more space for auto completion. Here is my minimal vimrc:

set wildmenu
set wildmode=longest:full,full
set wildoptions=pum

enter image description here

fuzzy is a good option, but it does not work with external programs, which is a deal breaker for me (fixed in patch 9.0.0089).

1
0

There's now (for Vim versions >= 9.1) vimsuggest for command-line auto-completion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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