30

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!

1
  • I am also looking to have a buffer list below (or above) the nerdtree pane. I will try to remember to update this post if I find a good solution (but thanks for asking anyway) Jun 7, 2012 at 22:38

3 Answers 3

8

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.

7
  • Thanks for your suggestions. It looks like BufferGator and SelectBuf are both at least close to the functionality I'm after, although they might need some tweaking to get things going. I definitely appreciate the concern about wasting space, but with my current use case I have one GVim instance open for hours at a time with many files open at once, hopping between them as needed. For these circumstances, a persistent buffer list is extremely helpful. I will, however, take some time to learn about the more typical Vim approaches to buffer management.
    – asfallows
    May 3, 2012 at 23:13
  • I imagine that you work on a big monitor. Whatever system you choose, you would still need to 1. switch to the bufferlist, 2. select a buffer, 3. hit a key to jump to it whether the bufferlist is already visible or not. Using an "on-demand" buffer switcher is thus just as effective as keeping a bufferlist open and it saves space.
    – romainl
    May 4, 2012 at 7:03
  • 1
    I definitely appreciate that reasoning, which is why I'm not too apprehensive about the possibility that the exact config I'm describing here might not be possible. The only major advantage a persistent buffer list has is that it takes 0 keystrokes to check which buffers are open, a piece of information I find valuable and also find myself very bad at keeping in short-term memory. (And yes, I do work on a fairly big monitor.)
    – asfallows
    May 4, 2012 at 12:42
  • @romainl, what vimrc command did you use to map ,b to search buffers with ctrlp?
    – snowbound
    Jan 23, 2015 at 14:06
  • 1
    @snowbound, FWIW I've stopped using CtrlP or any other similar plugins some time ago. Anyway, my command was nnoremap ,b :CtrlPBuffer<CR>.
    – romainl
    Jan 23, 2015 at 14:12
6

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

Screenshot

3
  • Thanks for the reply - I'd found MiniBufExplorer, and it looks like it's extremely good at what it does, but it doesn't meet the conditions I described for how I'd like to manage buffers. If it turns out there's no good way to do what I'm trying to do, or I decide that it's not the right way to do it, MBE is pretty high on my list for things to try next.
    – asfallows
    May 3, 2012 at 20:20
  • 1
    The only condition that is not met is that the list is on the left. I agree, MiniBufExplorer is at the top (where it doesn't waste as much space as on the left). Or maybe I misunderstood your requirements.
    – Marco
    May 3, 2012 at 20:28
  • With my current setup, having the list of buffers on the left as depicted is actually an improvement of space usage, because NERDTree is open at all times but doesn't always us the full vertical. Sharing that space with a buffer list would be nice. It's worth noting that this is how I use GVim, and I would not want a persistent left column if I were using Vim in the console. Most of my console use of Vim is "open file, make quick edit, close vim"
    – asfallows
    May 3, 2012 at 20:39
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .