How to run “gg=G” on several files?

六月ゝ 毕业季﹏ 提交于 2019-12-11 23:46:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!