bufdo and tabs

97 views
Skip to first unread message

Roy Fulbright

unread,
Nov 14, 2012, 2:10:47 AM11/14/12
to Vim User Group
I'm using gvim 7.3.600 on Windows 7.
 
I have three files opened in tabs (tab1=a.txt, tab2=b.txt, tab3=c.txt).
All three files contain the string 'abc'.
 
When I use :bufdo :%s/abc/def/ I get message E37: No write since last
change (add ! to override).
 
When I use :bufdo! :%s/abc/def/ all files are changed, but
now tab1 and tab3 both contain c.txt. What happened to a.txt in tab1?
 
If I do :wa then exit and look at the files, all three files are changed.
It's tab1 displaying the same file as tab3 after the :bufdo! that's puzzling.
 
Is this a bug or am I missing something regarding bufdo and tabs?
 
Thanks.

Marcin Szamotulski

unread,
Nov 14, 2012, 4:13:36 AM11/14/12
to vim...@googlegroups.com
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

I think this is expected. The bufdo command does the job in the current
window, and the last file it operates on is the c.txt. Thus it will
leave it in the current window (see :help bufdo). To avoid the E37
error you can also use:
set hidden

Best,
Marcin

Ben Fritz

unread,
Nov 14, 2012, 9:31:37 AM11/14/12
to vim...@googlegroups.com
It's not a bug. I think you may be missing something regarding windows, tabs, and buffers. http://vim.wikia.com/wiki/Buffers has a nice overview.

It sounds like you expect bufdo to operate on all TABS in your Vim, rather than all BUFFERS, and you just happen to have a single window open in each tab with a different buffer in each case. The :tabdo command will be close to what you want but if you have multiple windows in a tab or a tab with a duplicate buffer it still may do something unexpected. If you know you have exactly one window per tab with a unique buffer in each window, there will be no problem.

You can also open up a tab containing all open buffers and run a windo on that tab:

:tabnew
:sball
:windo WhateverCommandYouWant

Roy Fulbright

unread,
Nov 14, 2012, 10:21:36 AM11/14/12
to Vim User Group

 
> Date: Wed, 14 Nov 2012 06:31:37 -0800
> From: fritzo...@gmail.com
> To: vim...@googlegroups.com
> Subject: Re: bufdo and tabs
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
Thanks for the quick response. The :tabdo command is what I needed.
 
Reply all
Reply to author
Forward
0 new messages