Tobias
Tobias

Reputation: 2139

Autoformat code in Eclipse when entering semicolon or brace

Coming from Visual Studio, I'm used to getting my code auto-formatted whenever I enter a semicolon or a closing curly brace. Is it possible to do the same with Eclipse in the JavaScript editor?

Upvotes: 5

Views: 4001

Answers (3)

anilkjb
anilkjb

Reputation: 41

Use Ctrl+A to select your code, then press Ctrl+i, this will make code indentation properly for javascript code in eclipse kepler.

Upvotes: 3

user1486147
user1486147

Reputation:

I don't have the JavaScript plugin but I'm assuming it works the same such that Ctrl + I formats selected code to the correct indentation. I hope this is what you mean by formatting. Not too familiar with JavaScript so unsure of the best format.

Example, in Java:

public static void main(Strings[] args) {
boolean format = false;
if (format) {
for (int i = 0; i <10; i++) {
System.out.println("Hello World" + i);
}
}
}

Goes to:

public static void main(Strings[] args) {
    boolean format = false;
    if (format) {
        for (int i = 0; i <10; i++) {
            System.out.println("Hello World" + i);
        }
    }
}

You can change the key binds for eclipse in Window > Preferences > General > Keys > Correct Indentation

Upvotes: 0

NimChimpsky
NimChimpsky

Reputation: 47280

You can get autoformatting for javascript :

right click project > javascript > code style > formatter

You may have to make sure it has a project facet of javascript, I can't remember if that is necessary.

Upvotes: -1

Related Questions