How do I make Tab trigger wildmenu completion inside a custom mapping?
Answer
set wildcharm=<Tab>
Explanation
By default, pressing <Tab> in a : mapping inserts a literal tab character rather than triggering wildmenu completion. Setting 'wildcharm' to the same key as 'wildchar' (usually <Tab>) tells Vim that that key should activate completion even when typed inside a mapping.
This unlocks a common power-user pattern: a mapping that pre-fills a command and then lets you interactively complete the rest with Tab.
How it works
'wildchar'is the key that triggers completion when typing manually at the command line (default:<Tab>)'wildcharm'is the key that triggers completion when the command line is opened from a mapping- Without
wildcharm,<Tab>in a mapping is treated as a literal character
Example
Add to your vimrc:
set wildcharm=<Tab>
nnoremap ,e :e <Tab>
Now pressing ,e opens the :e prompt and immediately displays the wildmenu file browser. You can continue typing or pressing Tab to navigate directory contents interactively.
Another practical mapping:
nnoremap ,b :b <Tab>
This lets you pick from the buffer list with completion rather than memorising buffer numbers.
Tips
wildcharmmust be set to the same character aswildcharfor intuitive behaviour; any other character works too but is unusual- Works best with
set wildmenuandset wildmode=longest:list,full - Combine with
set wildignoreto suppress noisy completions (e.g.*.o,*.pyc) - This setting has no effect at the interactive command line — only inside mappings that programmatically open it