Sławosz
Sławosz

Reputation: 11687

Indent code in the same way as = in ex mode in Vim

How can I indent code in command mode in Vim in the same way as = in visual mode?

Upvotes: 3

Views: 566

Answers (2)

Sam Brinck
Sam Brinck

Reputation: 901

== will fix indentation on a single line
=% will fix indentation to the matching brace (if the cursor is on a brace)
gg=G will go to the top of the file gg and then fix indentation to the bottom of the file =G

summary - = is followed by an movement key and will fix indentation in the range specified by the motion.
This sheet shows the movement key in green, as you can see there are many options

Upvotes: 1

sidyll
sidyll

Reputation: 59287

Try the normal command == with a range:

{range}normal! ==

It will apply == to each line in the passed range. You can also try things with the gv= command, to reuse last selection; and take a look in the helpful '< and '> marks.

Upvotes: 11

Related Questions