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
  • 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. – user1686 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

Have you tried :source?

vim example.html -c "source /tmp/a.script"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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