2Qs: tab-specific buffers and buffer grep

7 views
Skip to first unread message

Eric Tetz

unread,
Feb 6, 2008, 1:59:43 PM2/6/08
to Vim list
1. I often find myself wishing a tab could have an independent buffer
list, so I could use tabs to organize a large working set of files
into manageable subsets. Is this possible now? Maybe in the future?

2. Is there a built-in way to search for a pattern in all currently
loaded buffers?

Cheers,
Eric

Ben Schmidt

unread,
Feb 7, 2008, 8:49:59 AM2/7/08
to vim...@googlegroups.com, Vim list
Eric Tetz wrote:
> 1. I often find myself wishing a tab could have an independent buffer
> list, so I could use tabs to organize a large working set of files
> into manageable subsets. Is this possible now? Maybe in the future?

It's not possible now.

I personally doubt it would be planned for future inclusion either, but I'm most
certainly not the authority on that!

> 2. Is there a built-in way to search for a pattern in all currently
> loaded buffers?

I'm pretty sure there isn't.

I'd love to make a feature request, though...could :vimgrep be modified so that
the filename is optional, and if omitted, it will use the text of the current
buffer (quite possibly not saved to disk). Then you could do

:call setqflist([])
:bufdo vimgrepadd /whatever/

to achieve that.

Even without the feature built in, it wouldn't be too hard to make a vimscript to
do it, though. I think this might do:

:call setqflist([])
:bufdo g/whatever/call
\ setqflist([{'bufnr': bufnr('%'), 'lnum': line('.'), 'text': getline('.')}],'a')

It wouldn't take too much more work to make this into a custom command, and it
could do with various improvements, I'm sure.

Ben.


Send instant messages to your online friends http://au.messenger.yahoo.com

Ben Schmidt

unread,
Feb 7, 2008, 8:56:46 AM2/7/08
to vim...@googlegroups.com
Eric Tetz wrote:
> 1. I often find myself wishing a tab could have an independent buffer
> list, so I could use tabs to organize a large working set of files
> into manageable subsets. Is this possible now? Maybe in the future?

Further to my earlier post...I wonder whether local argument lists would suit your
purposes? Quite possibly not, I guess, but it's worth mentioning. They are
documented around

:help :arglocal

Hari Krishna Dara

unread,
Feb 7, 2008, 2:31:43 PM2/7/08
to vim...@googlegroups.com

On Fri, 8 Feb 2008 at 12:49am, Ben Schmidt wrote:

>
> Eric Tetz wrote:
>> 1. I often find myself wishing a tab could have an independent buffer
>> list, so I could use tabs to organize a large working set of files
>> into manageable subsets. Is this possible now? Maybe in the future?
>
> It's not possible now.
>
> I personally doubt it would be planned for future inclusion either, but I'm most
> certainly not the authority on that!

At the simplest, it should be possible to enhance one of the buffer
explorer scripts such that they will keep track of the original tab
number in which the buffer was created, but the lack of identity for
tabs and the lack of certain tab events would make it rather tricky to
implement.

>
>> 2. Is there a built-in way to search for a pattern in all currently
>> loaded buffers?
>
> I'm pretty sure there isn't.
>
> I'd love to make a feature request, though...could :vimgrep be modified so that
> the filename is optional, and if omitted, it will use the text of the current
> buffer (quite possibly not saved to disk). Then you could do
>
> :call setqflist([])
> :bufdo vimgrepadd /whatever/
>
> to achieve that.
>
> Even without the feature built in, it wouldn't be too hard to make a vimscript to
> do it, though. I think this might do:
>
> :call setqflist([])
> :bufdo g/whatever/call
> \ setqflist([{'bufnr': bufnr('%'), 'lnum': line('.'), 'text': getline('.')}],'a')
>
> It wouldn't take too much more work to make this into a custom command, and it
> could do with various improvements, I'm sure.
>

I attempted to do this long back in my greputils plugin:

http://www.vim.org/scripts/script.php?script_id=1062

The :BufGrep, :ArgGrep and :WinGrep commands are meant for this, but
something might have been broken lately and some functionality might
not be working correctly, sorry haven't been working much in vim lately
so not sure about the current state myself. I still recommend giving it
a try.

--
Hari

Eric Tetz

unread,
Feb 7, 2008, 2:45:53 PM2/7/08
to vim...@googlegroups.com
On Feb 7, 2008 5:49 AM, Ben Schmidt <mail_ben...@yahoo.com.au> wrote:
> I personally doubt it would be planned for future inclusion either, but
> I'm most certainly not the authority on that!

That's a bummer, because it's potentially a very powerful feature that
is currently nothing more than a way to save window layouts.

> Even without the feature built in, it wouldn't be too hard to make a

> vimscript to do it, though. i think this might do:

But that won't let you search through buffer text that has not been
saved to a file, right? I'd like to be able to say "vimgrep pattern
%*" (or something like that) which meant "grep loaded buffers".

Yegappan Lakshmanan

unread,
Feb 7, 2008, 2:53:57 PM2/7/08
to vim...@googlegroups.com
Hi,

On Feb 7, 2008 5:49 AM, Ben Schmidt <mail_ben...@yahoo.com.au> wrote:
>

> Eric Tetz wrote:
> > 1. I often find myself wishing a tab could have an independent buffer
> > list, so I could use tabs to organize a large working set of files
> > into manageable subsets. Is this possible now? Maybe in the future?
>
> It's not possible now.
>
> I personally doubt it would be planned for future inclusion either, but I'm most
> certainly not the authority on that!
>
> > 2. Is there a built-in way to search for a pattern in all currently
> > loaded buffers?
>
> I'm pretty sure there isn't.
>
> I'd love to make a feature request, though...could :vimgrep be modified so that
> the filename is optional, and if omitted, it will use the text of the current
> buffer (quite possibly not saved to disk). Then you could do
>
> :call setqflist([])
> :bufdo vimgrepadd /whatever/
>
> to achieve that.
>
> Even without the feature built in, it wouldn't be too hard to make a vimscript to
> do it, though. I think this might do:
>
> :call setqflist([])
> :bufdo g/whatever/call
> \ setqflist([{'bufnr': bufnr('%'), 'lnum': line('.'), 'text': getline('.')}],'a')
>

You can also use the following commands:

:call setqflist([])
:bufdo g/<pattern>/caddexpr expand("%") . ":" . line(".") . ":" .
getline(".")

- Yegappan

Ben Schmidt

unread,
Feb 7, 2008, 6:32:02 PM2/7/08
to vim...@googlegroups.com
>> Even without the feature built in, it wouldn't be too hard to make a
>> vimscript to do it, though. i think this might do:
>
> But that won't let you search through buffer text that has not been
> saved to a file, right?

No, it should work on unsaved text. It just uses the :g command which searches the
text in the buffer, executes a command on every line that matches, and the command
I gave it was to add to the quickfix list.

Cheers,

Reply all
Reply to author
Forward
0 new messages