1

In vim, gg=G does a great job re-indenting your current file and I'd like to do that on several files.

I would like to do something like this:

files=`find $1 -type f`
for file in $files
do
    vim -e -s -n "+gg=G|wq" $file
done

The problem is that gg=G is not a command (if you type :gg=G in vim, it throws an error), so it doesn't work...

Creak
  • 4,021
  • 3
  • 20
  • 25

2 Answers2

3

I think I found it! (of course 10 minutes after I posted the question, even though I searched before for 4 hours)

files=`find $1 -type f`
for file in $files
do
    vim -e -s -n "+normal gg=GZZ" $file
done
Creak
  • 4,021
  • 3
  • 20
  • 25
1

Open the files you want to modify in vim

vim *

Then use :bufdo to execute a command in all loaded buffers

:bufdo normal 0=G

Finally, save all files and exit

:wqa
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293