In Vim, what is the command to correct the indentation of all the lines?
Often times I\'ll copy and paste code into a remote terminal and have the whole thing messed
The master of all commands is
gg=G
This indents the entire file!
And below are some of the simple and elegant commands used to indent lines quickly in Vim or gVim.
To indent the all the lines below the current line
=G
To indent the current line
==
To indent n
lines below the current line
n==
For example, to indent 4 lines below the current line
4==
To indent a block of code, go to one of the braces and use command
=%
For vi Editor, use :insert. This will keep all your formatting and not insert auto-indenting.Once done press escape to view the actual formatted file otherwise you'l see some garbage characters. like ^I e.g:
public static void main(String[] args) {
^I
^I System.out.println("Some Garbage printed upon using :insert");
}
press escape and then type below combinations fast:
gg=G
You can create a mapping to do this for you.
This one will auto indent the whole file and still keep your cursor in the position you are:
nmap <leader>ai mzgg=G`z