31

I've investigated a few ways to maintain a list of open buffers in Vim, and some of them are very good, but none of them seem to behave the way I'd like. It's very possible that nothing like what I want exists, and it can't hurt to ask.

I've been using NERDTree in GVim, and I like the idea of putting the information in a slender left-hand window. I've put together a handy diagram for how I'd like my environment to look:

|--------|---------------------------------------|
|        |                                       | 
|        |                                       | 
|NERDTree|           Windows                     | 
|        |                                       | 
|        |                                       | 
|        |                                       | 
|--------|                                       |
|        |                                       | 
|        |                                       | 
|  List  |                                       | 
|   of   |                                       | 
|  Open  |                                       | 
| Buffers|                                       | 
|        |                                       | 
|        |                                       | 
|--------|---------------------------------------|

So my question is: Is there a vim-native or plugin-enabled way to maintain a list of currently open buffers and select/edit/close from that list, inside a window similar to NERDTree?

I understand that this approach may be incongruous with the Vim way of doing things, and if you feel like I'm missing something about how to manage multiple files in a Vim session, please leave a comment with suggestions!

asfallows
  • 1,061

3 Answers3

9

Did you search vim.org's plugin repository? There are dozens of buffer switching plugins for you to choose from like BufferGator or SelectBuf. Alternatively, most of them are compiled in a nice list on the Vim wiki.


As you alluded in the last part of your question that kind of system is not to everyone's taste.

I hate having all those menus, buttons and lists of this or that open at all times: a list of open buffers is only useful when you actually need to jump to another buffer, leaving such a list open seems like a waste of space to me. The same can be applied to supercharged statuslines as well.

I use the same plugin for quicly switching between buffers and quicly exploring the filesystem around the file I'm currently editing. Invoked with ,f (files) or ,b (buffers), the window disappears when I'm done. Perfect. There are other similar plugins, try them all if you like that idea.

EDIT

I feel compelled to add an animated GIF of CtrlP in action, switching buffers:

Switching buffers with CtrlP

ENDEDIT

The native :sb <Tab> is also pretty neat but less sexy. It doesn't support fuzzy matching but it has some big advantages: it's built in and it works like :e <Tab>, :vs <Tab> and so on.

romainl
  • 23,415
6

I can highly recommend the MiniBufExplorer. See also an alternative to minibufexplorer?

Screenshot

Marco
  • 4,444
2

There a way to do exactly that using winmanager plugin. In this screenshot I combine both NERDTree and MiniBufExpl (github: techlivezheng/vim-plugin-minibufexpl, latest commit atm 349a9fbb) plugins on the same vertical split and toggle it with F4. In theory this solution should work for any other plugins combination.

Example of my .vimrc

" {{{ MiniBufExpl config
let g:miniBufExplVSplit = 20 " open in vertical
let g:miniBufExplSplitToEdge = 0 " open relative to previous window (NERDTree)
" }}} MiniBufExpl config

" {{{ winmanager config " register the plugins let g:NERDTree_title='NERD Tree' let g:MiniBufExpl_title='MiniBufExpl'

" set the layout let g:winManagerWindowLayout='NERDTree|MiniBufExpl'

" handler for NERDTree function! NERDTree_Start() exec 'NERDTree' endfunction

" handler for MiniBufExpl function! MiniBufExpl_Start() exec 'MBEOpen' endfunction

" mapping to toggle the split to F4 nmap <F4> :WMToggle " }}} winmanager config

Problems:

  • NERDTree doesn't use the buffer that winmanager creates but opens in its own...
  • ...therefore winmanager buffer stays unused
  • MiniBufExpl doesn't update itself properly when jumping between buffers

The behavior I have achieved is far from perfect but it's a good start.

rasmusm
  • 103
svlasov
  • 163