2

I am not that much aware of Eclipse Shortcuts.

I copied code from some link and I pasted in Eclipse Indigo but it is coming like

"public String doLogin() throws ApplicationException{ long  executionStartTime = System.cu... }"

I want to format it in java style like

public String doLogin() throws ApplicationException{ 
    long  executionStartTime = System.cu... 
}

I google it and found few shortcuts like,

"Shift + Tab" , "Ctrl + I", "Ctrl + Shift + F". but is not giving me the behavior I want.

is there I need to add custom formatter or I am expecting more.

6 Answers 6

3

You can format text using the Ctrl+Shift+F shortcuts.

You can use Ctrl+A to select all text or you can format only several lines (which you have selected).

There is a caveat however: If your code does not compile the formatting does not work. I don't know whether this is intentional or a bug.

You may want to enable auto-formatting in Eclipse it is a handy feature I usually use:

enter image description here

You can find the formatter settings here:

enter image description here

I also recommend the Eclipse Color Theme plugin!

Sign up to request clarification or add additional context in comments.

Comments

2

With default key mapping Ctrl+Shift+F should format your code (current class or selection if any). Of course syntax has to be valid.

You should be able to access that feature using the menu Source > Format where shortcut is displayed if existing.

1 Comment

You are correct, I had mapping as well present, but somewhere my key was not working. when I tried "Source > Format" it gave me needed behaviour.
1

Type Ctrl+Shift+L to get list of shortcuts in Eclipse.... and to format Ctrl+Shift+F

type Ctrl+Shift+L to get the list of shortcuts

Comments

0

You can create your own formatter:

Window -> Preferences -> Java -> Code Style -> Formatter.

Comments

0

"Ctrl + Shift + F" should work but make sure you remove " from start and end of the code you copied.

Comments

0

select all text using ctrl + a

and press

Ctrl + Shift + F

to format text

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.