Tuesday, 20 June 2017

Automatic Indentation of Code in Vim

Indentation is very important as it increases the readability of the codea and is considered to be a good programming practice. But a lot of times you may have to get some code that is not indented, and it is really irritating to mannualy indent each line. Vim provides a very eays way to indent your code just with unbelievably few keystrokies.

gg=G

is will indent your code from beginning of the file till the end of the file. Note that here gg means go to the starting of the file and = means to indent and G is for the end of the file. Puting it together we can read it as "indent the code from first line till the last line."

Similarly, to order to indent the current line, just place your cursor anywhere in that line and press
==
This will indent the current line.

No comments:

Post a Comment