Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I indent a particular block of code in Vim? [duplicate]

Tags:

vim

format

In Aptana Studio when I have to format code I choose a block of code and then press Ctrl + Shift + F.

What is the equivalent of this in Vim?

I.e., say we got the below lines of code:

function() {
var test = "Hello, World!";
var test2 = "Hello, World! Again";
}

The final output I want to see is well formatted code like below:

function(){
  var test = "Hello, World!";
  var test2 = "Hello, World! Again";
}
like image 545
runtimeZero Avatar asked Dec 16 '22 00:12

runtimeZero


1 Answers

If Vim knows the language you are using, you can use the = key to auto-indent a section of code.

Within the block type =a}, or to auto-indent the entire file by typing gg=G.

like image 122
Matt Woelk Avatar answered Dec 27 '22 11:12

Matt Woelk