I'm Rituraj, a Developer @Nagarro. founder of Maddyzone. JavaScript, Angular, Node.

Buy Me a Coffee at ko-fi.com

Enable and disable code indentation in vim

In vim by default code indentation are not enable so to enable the code indentation in vim we need to set it manually also we can disable.Here i am describe how to enable and disable code indentation in vim.

This command will not run in insert and visual mode.It will work in command mode. for command mode press ESC key then write below

##Automatic Indentation


Enable code indentation in vim

:filetype indent on

Disable code indentation in vim

:filetype indent off

###If you want by default vim load this above setting then write in your .vimrc file

filetype indent on

like as we mention on above.


Adjusting and Correcting Indentation


###In general, ={motion} will align code to an indentation level.

S.N.commandWork
1==align the current line
2=i{align the inner block
3=%align to the matching parenthesis/bracket under the cursor
4=14j or 14==align the next 14 lines
5=Galign to the end of the file
6vG=same thing, align to the end of the file (but using visual mode)
7vjjj=align four lines (using visual mode)
8gg=Galgin code in full file
here = the indent command can take motions. So, By gg we go to the start of the file, = to indent and by G to the end of the file, gg=G

Thanks!


Rituraj Ratan

I'm Rituraj, a Developer @Nagarro. Founder of Maddyzone .