VIM, Run a command on multiple files

Andrew WC Brown picture Andrew WC Brown · Aug 19, 2011 · Viewed 10.4k times · Source

I have a bunch of sass files and my designer used the wrong syntax. I wanted :margin-top 1px but he did margin-top: 1px

So I easily wrote a sub command:

:rubydo sub! /([\w-]+):/,':\1'

So that works and fixes all the colons and moves them in the place I want. I have about 50 sass files in a stylesheets directory. How can I run this command on all my files in one shot? I'm not really sure how to go about this in vim. Maybe something to do with grep? I couldn't tell ya.

Answer

Niloct picture Niloct · Aug 20, 2011

See this: http://vimdoc.sourceforge.net/htmldoc/editing.html#:argdo

I learned this command right now, but the help is clear.

Go for:

:args *.css
:argdo %s/\([[:alpha:]-]\+\):/:\1/ge | update