VIM: indent multiple files at once

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

VIM: indent multiple files at once

Post 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
Post Reply