Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Yeah, I know, I could just use sed. But lets assume I'm some sort of sicko. A masochist if you will..

I have a file, /tmp/a.script, containing:


(I snarfed them from my vim history)

I would very much like vim to execute those commands against a file, say example.html.

But, I can't figure out how to execute this script against the file.

I'm aware of the -c command line argument. But it only executes a single command, I want to execute all these commands.

Any ideas?

Answer is below, for reference, a quick sed way to do it would be:

for i in *.html ; do
  sed -i'' -e 's_"taxonomy\.php[^"]*\([0-9]\)_"\1.taxonomy_g'  $i
  sed -i'' -e 's_"rtf\.php[^"]*\([0-9]\)_"\1.rtf_g' $i
  sed -i'' -e 's_"csv\.php[^"]*\([0-9]\)_"\1.csv_g' $i
  sed -i'' -e 's_"xml\.php[^"]*\([0-9]\)_"\1.xml_g' $i
  echo $i
share|improve this question
Notes on the sed example: 1) -i'' is equivalent to -i due to the way Bash processes quotes; 2) You can give -e multiple times, or separate the s/// commands with semicolons, to avoid multiple sed calls; 3) You can give *.html directly to sed. – grawity Mar 7 '12 at 21:24
The quotes, I got into the habit of doing that a while back, I'm running ZSH, I might have gotten some funny behavior before with that. Your comments about sed are spot on, I would have done it that way but wanted to have a more easily understood example. Not everyone is a grawity ninja! – Bryan Hunt Mar 8 '12 at 12:41
up vote 2 down vote accepted

Have you tried :source?

vim example.html -c "source /tmp/a.script"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.