Page 1 of 1

VIM: indent multiple files at once

Posted: Tue Dec 08, 2020 3:02 pm
by peter_b
I often use vim to quickly beautify / pretty-print structured text - like XML or programming code, etc:

In VIM this is:

Code: Select all

gg
=G
gg: Go to top
=: indent
G: until bottom.


In order to do this with multiple files, do the following:

1) Open the files you want to indent in tabs.
For example all XMLs in the current folder:

Code: Select all

$ vim -p *.xml

2) Now use "tabdo" command to apply a command to all open tabs.
But how to translate the "gg=G"?
It works by putting the command "normal" before:

Code: Select all

:tabdo normal gg=G