Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a different buffer list for each tabs in Vim?

Tags:

Is it possible to kind of "attach" a list of buffers to particular tabs within Vim? I am currently using MiniBufferExplorer, which shows all buffers in nice tabs. It can be combined using standard vim tabs but the plugin's buffer list contains all the buffers and using tabs become a bit useless. Here's an example of what I'd like:

Tab A contains a buffer list of:

  • FileA
  • FileB
  • FileC

Tab B contains a buffer list of:

  • FileD
  • FileE
  • FileF

Currently what I have is this:

Tab A contains a buffer list of

  • FileA
  • FileB
  • FileC
  • FileD
  • FileE
  • FileF

Tab B contains a buffer list of:

  • FileA
  • FileB
  • FileC
  • FileD
  • FileE
  • FileF

When speaking about "buffer list" I mean the tab listing the minibuffer plugin gives.

Any workaround to achieve this?

like image 333
Steven Rosato Avatar asked Feb 22 '10 01:02

Steven Rosato


People also ask

How do I switch between buffers in Vim?

Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.

How do I rearrange tabs in Vim?

You can use :tabmove followed by the tab number to move past. For example, :tabmove 3 will make the current tab move past the 3rd. :tabmove 0 moves to the beginning and :tabmove (without a number) moves to the end.

Where are Vim buffers stored?

For example, when you start VIM without supplying a file for it to open, VIM starts with an empty buffer. If you want to save the changes to that buffer, then you have to tell VIM what file to write those changes to. So again, a buffer resides in memory.


1 Answers

I cant think of any Tab based buffer explorers out there but vimscript has got plenty of functions to track of buffers (:he function-list) . I just knocked this up for the hell of it. It might get you to what you want . It just keeps track of tabs in a vim dictionary. You will need to flesh out the :TabExplorer function or patch the filtered list (ie. g:TabExplorer[tabpagenr()]) into the minibuf plugin

Save it as ~/.vim/plugin/tabexplorer.vim and source it at startup.

let g:TabExplorer = {}

func! StoreBufTab()
    if !has_key(g:TabExplorer, tabpagenr())
        let  g:TabExplorer[tabpagenr()] = []
    endif

    if index(g:TabExplorer[tabpagenr()], bufname("%")) == -1 && bufname("%") != ""
        call add (g:TabExplorer[tabpagenr()],bufname("%"))
    endif
endfunc

func! DisplayTabExplorer()
    4split
    enew
    call append(".",g:TabExplorer[tabpagenr()])
endfunc

au BufEnter * call StoreBufTab()

command! TabExplorer call DisplayTabExplorer()
like image 184
michael Avatar answered Oct 12 '22 08:10

michael