Take a look at the enum:
enum TestEnum
{
First = 1,
Second = 2,
Unknown = 3,
TestTestTest = 100,
Zero = 0,
Foo = 123,
}
How can I use the whole power of Vim to reformat it?
enum TestEnum
{
First = 1,
Second = 2,
Unknown = 3,
TestTestTest = 100,
Zero = 0,
Foo = 123,
}
Personally, I'm moving line by line and tabbing. It is the same as I would do that in any regular editor. How to do that the right way?
The same for class members:
class Foo
{
SuperFoo foo1;
RegularFoo foo2;
SuperiorFoo foo3;
YetAnotherFoo foo4;
Bar bar;
}
to something like
class Foo
{
SuperFoo foo1;
RegularFoo foo2;
SuperiorFoo foo3;
YetAnotherFoo foo4;
Bar bar;
}
Thanks
It's possible to reformat an entire file, or a section of a file, using Vim's built-in = filter. Vim veterans often find this operator to be one of the most useful in their repertoire, but so common that it becomes second-nature and is rarely mentioned. In normal mode, typing gg=G will reindent the entire file.
Select the block of code you want to format with V or the like. Format by typing :! indent .
To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing. If you set the auto-indent feature in Vim in command mode, it does not persist upon closing the editor.
You can harvest from two plug-ins that can do this stuff:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With