Vim question

Siddharth Patwardhan sidd at
Tue Jan 13 23:58:01 MST 2009

On Tue, 2009-01-13 at 21:39 -0700, Stephen Weeks wrote:
> Not long ago, Alec Shaw proclaimed...
> > Every so often I have files with spaces in their names and I want to 
> > rename them with underscores for the spaces.
> > The way I have normally done the the renaming is by putting the output 
> > of an ls into a file and editing the file in vim
> > to make it into a script.
> > I usually do ":g/.*/s//mv & &/ " and then hand editing the paces to 
> > underscores in the third column.
> > There has to be a better way.
> > Is it possible to have vim do the substitution on the third column 
> > without affecting the first column?
> > Actually as I think about it maybe a bash or ksh (after years of use ksh 
> > is still my preferred shell) script
> > would be better.  Maybe a "for f in *; do mv $f $g; done" but how do I 
> > get $g from $f with spaces substituted?
> > 
> > Thanks for any suggestions.
> > Alec Shaw
> I use the rename command for this.  The syntax is: rename FROM TO FILE...
> So, for this example:
> rename ' ' _ *

Yes... I've also found the 'rename' command to be quite useful for 
mass-renaming of files. It is especially powerful because of its 
support for Perl-style regex substitution:

rename 's/\s+/_/g' *

-- Sid.

More information about the PLUG mailing list