问题
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...
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/28403036/how-to-run-gg-g-on-several-files