How to Reindent Lines in Vim

Updated on

Reindenting files helps keep code neat. In Vim, you can reindent an entire file from normal mode (press ESC to get there) by typing gg=G.

You can reindent multiple files with the following commands, in this case reindenting all JavaScript files in the current directory:

:ar *.js
:argdo norm gg=G
:wall

You can find more information about those commands with :h like this:

:h ar

See the Vim wiki for more ideas.

Tagged with: Programming Vim

Feedback and Comments

What did you think about this page? Do you have any questions, or is there anything that could be improved? You can leave a comment after clicking on an icon below.