2

To switch between buffers without installing any plugins, a good way is to type

:b <tab>

Which shows all the current buffer names in status bar and you can pick one using cursor keys and enter.

But :b <tab> is 5 keystrokes and I would like to map it to a <leader>.

But setting the following is not working.

:nnoremap <Leader>. :b <Tab>

It shows ":b ^I" in status bar and doesn't actually open the buffer names on status bar.

Anyone knows why?

  • the buffers (note the 's') command lists the buffers, while the buffer (no 's') command, when it is given an option, will change which buffer is shown in the window. – lornix Jul 6 '12 at 0:36
4

You need to set the wildcharm setting. Try this:

set wildcharm=<Tab>
nnoremap <leader>. :b <Tab>

At least this works here.

  • Wow! Thank you. I've never heard/read about it. – romainl Jul 6 '12 at 7:56
  • YES! That fixed it!!! OSX on MacBook. Thank you:-) – CDR Jul 8 '12 at 5:50
1

I think that it has something to do with <tab> not being a real argument for :b.

If you drop the tab, as in nnoremap <leader>. :b<space> you can hit <tab> to get the menu.

You are down to 3 keystrokes to summon the menu but you may still have to hit <tab> more times to select the correct buffer and hit <CR>. That's a minimum of 4 keystrokes if you want the 1st buffer which is quite nice but what if you want the 7th or 12th buffer?

May I suggest another way?

nnoremap <leader>. :ls<CR>:b<Space>

With this mapping, a list of buffers (:ls) is displayed and the :b command is initiated, waiting for a buffer number as argument. That's 4 keystrokes (,.5<CR>), whatever buffer you want to jump to (well, if you have 10 or more buffers that would be 5 keystrokes but you get the point).

I don't know how you could make it shorter beside mapping a single key (like <F11> or whatever).

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.