1

is there a way to use vim as a command line tool? What I mean is, use it from the console (without opening a ncurses window) to run vim commands on file and save them. I need this because I usually run through all my files and do 'gg=G' to auto indent them.

Thanks

Guido
  • 2,571
  • 25
  • 37

1 Answers1

2

Here are listed two different ways to do that:

  • by using vim -s file-containing-commands file-to-edit

  • by using vim file "+:firstcommand" "+:secondcommand" ...

The first solution needs a file to be written beforehands; the second solution will launch vim and execute the commands, without leaving vim; you'll have to do that yourself, for instance adding a last command '+:x'

Community
  • 1
  • 1
giorgian
  • 3,795
  • 1
  • 30
  • 48
  • That's good for regular commands, but I needed to run gg=G on everything! This was my solution using your suggestion `vim file.c '+execute "normal gg=G"' +wq`. This is going straight to my bin folder ;). – Guido Apr 29 '13 at 20:50