Content

Observations from a West Coast family

The joy of :bufdo

Tuesday 27 January 2004 - Filed under Software

If you use vim, then you may have discovered that its documentation, while extensive, is nearly impenetrable. One operation I often have to do is

$ for x in [list of files]; do
> sed -e '[some substitution]' < $x > $x.bak
> mv $x.bak $x
> done
since most Unix-based editors don’t offer multi-file replace. It turns out that, sometime between 5.3 and 6.x, vim has added the :bufdo command, so this operation is much simpler as
  • you needn’t leave the editor, and
  • you needn’t maintain a list of files, provided you’ve opened them all in the editor.
I’m posting to share this small tip, since when I canvassed a few folks at the office, no one seemed to have heard of :bufdo. (See “impenetrable documentation”, above.)

2004-01-27  »  Stephen

  • Phil Harman

    Cool. Although I’d generally have done this in the past …

    $ for x in [list of files]; do

    mv $x $x.bak sed -e ‘[some substitution]‘ $x done

    … and I suspect that’s what you meant – unless you write much more reliable sed scripts than me! :)