2

I'm trying to create a key mapping that makes switching buffers quicker and easier - something like:

set wildmenu
nnoremap <Tab> :buffer<space><Tab>

The problem is, this mapping leaves me at the end of a command line that looks like:

:buffer ^I

when I want it to start tabbing through the list of buffers.

I've searched the help files and Google, and tried many different combinations of :execute and :normal, all to no avail. Is there a way to do what I'm asking, or am I stuck with the following, two-keypress solution?

set wildmenu
nnoremap <Tab> :buffer<space>

Then, pressing <Tab><Tab> will do what I want.

2 Answers 2

2

You need to set wildcharm=<Tab> and the following mapping will do what you want:

nnoremap <Tab> :buffer <Tab>

See :h 'wildcharm' and :h 'wildchar':

  • wildchar defines the key which triggers the wildmenu
  • wildcharm is like wildchar but it works in macros and mappings.
0
3

You need the wildcharm option:

set wildcharm=<C-z>
nnoremap <key> :buffer<Space><C-z>

See :help 'wildcharm.

4
  • Seems like we get the same answer at some seconds of difference :-) But I have a question: Why do you suggest to use <C-z> as wildcharm and not <Tab> as OP wanted? Is it just a personal preference or is there another reason?
    – statox
    Oct 8, 2015 at 19:22
  • 2
    1. That's the value suggested in the doc. 2. wildcharm is only used in mappings anyway so it makes sense to use a special value to prevent confusion.
    – romainl
    Oct 8, 2015 at 19:33
  • My concern was more about incompatibility with other modes or this kind of stuff but your points make sense indeed.
    – statox
    Oct 8, 2015 at 19:37
  • Thanks, @romainl. statox beat you by only a minute. I went with the <Tab> as my wildcharm character
    – Phil R
    Oct 8, 2015 at 19:55

Your Answer

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

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