3

I'd like to map Leader+e in normal mode to showing the auto completions of files to edit.

I tried nnoremap <leader>e :e<space><tab>, but it shows :e ^I, where the tab gets rendered as ^I rather than triggering the auto completions.

Using nnoremap <leader>e :e<space> correctly prints :e but I obviously have to hit Tab manually in this case.

How can trigger the auto completions to show up in a key binding?

5

you can use :nnoremap <leader>e :call feedkeys(':e<space><tab>','t')<cr>

the t indicates to use the keys as typed (as opposed to coming from a mapping)

2

You could also give the same value to the 'wildchar' and 'wildcharm' options:

set wc=9
set wcm=9

9 is the decimal code of the Tab key.


For your particular issue, 'wcm' is probably the only option you need to set.

It determines which key must be pressed during the recording of a macro, or in the {rhs} of a mapping to start wildcard expansion in the command-line.

However, you should probably give it the same value as 'wc', otherwise you won't be able to replay a macro opening the wildmenu:

enter image description here

  • Upvoted, but I'm a bit confused by your mention of recording macros. As far as I can tell from the documentation (and experimentation) the wildcharm setting doesn't affect recorded macros? (The documentation for it does mention the word "macro", but like the rest of the documentation it uses that term to refer to mappings.) – Rich Feb 8 '18 at 11:01
  • @Rich On my machine, if 'wcm' is not configured like 'wc', the replay of a macro which opens the wildmenu doesn't work. I included a gif to show it. In it, I first give to 'wc' the value 9 (Tab key) and to 'wcm' the value 94 (C-z suggested in :h 'wcm). The replay of the macro (@q) fails to edit file2 like what was done during the recording. When I give to both options the same value, @q works as expected. – user786441 Feb 8 '18 at 11:30
  • @Rich Sorry I was wrong, 94 is not the decimal code of C-z. I should have used 26. But it doesn't change the result of the experiment. – user786441 Feb 8 '18 at 12:47
  • 1
    Thanks for the clarification! I made a mistake when I was testing it: my completion (after a single Tab) was a directory. So I got an "Illegal file name" error. Then when I played back the macro I got the same "Illegal file name" error. I interpreted this as the file name having been completed, but actually it was performing a bare :e and using the file name of the buffer (which had been set when recording the macro). Duh. – Rich Feb 8 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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