VIM: indent multiple files at once
Posted: Tue Dec 08, 2020 3:02 pm
I often use vim to quickly beautify / pretty-print structured text - like XML or programming code, etc:
In VIM this is:
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:
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:
In VIM this is:
Code: Select all
gg
=G
=: 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