Vim Tips Wiki
Advertisement

Switching buffers in Vim is a little painful as you don't realize how many buffers you have opened. This is mostly true while browsing a large source tree with cscope.

Put the following function in your vimrc to get a visual feedback of all your buffers while switching buffers.

function! DoBuff()
  execute "bnext"
  let buf = 1
  echon "    "
  while buf <= bufnr("$")
    echon "["
    if bufloaded(buf)
      echohl WarningMsg | echon bufname(buf) | echohl None
    else
      echon bufname(buf)
    endif
    echon "]  "
    let buf = buf + 1
  endwhile
endfunction
map <Esc>e :call DoBuff()<CR>

To change the key-mapping change map to a key of your choice (I use Esc-e)

Now using Alt-e will cycle between buffers and also provide a listing of your buffers while you switch.

Shot

Comments

Thanks for the contribution. I don't know if you are aware but we have a number of tips relating to buffers, with the most relevant being Easier buffer switching. In general, we like to keep related information in one place (or, where too complex for one tip, a small number of places). That makes the tips more useful for readers and easier to manage for editors.

I haven't had a chance to think about the tip in detail yet, but I have a couple of preliminary thoughts:

  1. What happens when you have a lot of buffers? Many people have far more than 10 buffers open at once.
  2. The tip maps <Esc>e but mentions Alt-e.
  3. Images can be useful but this one is too big since I think it is only the last line that is relevant. We can think about that later.

Later, we will discuss how best to handle the October proposed tips here. JohnBeckett 07:06, October 21, 2009 (UTC)

Advertisement