How do I trigger wildcard filename completion from inside a custom key mapping in Vim?
Answer
:set wildcharm=<C-z>
Explanation
The wildchar option (default <Tab>) triggers wildcard completion interactively on the command line. But <Tab> embedded directly in a mapping is awkward — it fires at map-definition time, not when the mapping runs. The wildcharm option solves this: it designates a separate character that triggers the same completion, and that character can safely appear in mapping definitions.
How it works
:set wildcharm=<C-z>— designate<C-z>(Ctrl+Z) as the completion trigger for mappings- Now you can embed
<C-z>in anynnoremaporcnoremapto fire the wildmenu - Useful for creating mappings that drop into a command with completion already active
Example
Add to your vimrc:
set wildcharm=<C-z>
nnoremap <leader>b :buffer <C-z>
nnoremap <leader>e :edit **/*<C-z>
With wildmenu enabled, pressing <leader>b immediately opens :buffer with the completion menu showing all open buffers.
:buffer [buffer1] buffer2 buffer3
Pressing <leader>e opens :edit **/* and immediately shows a fuzzy file picker.
Tips
wildcharmmust differ fromwildchar— using<C-z>avoids any conflicts since<C-z>(suspend) is unlikely to be used in mappings- Combine with
:set wildmenuand:set wildmode=list:longest,fullfor the best completion experience - The character can be any unused key —
<C-z>is the traditional recommendation in Vim's own help - This also works in
cnoremapfor building smart command-line helpers