Syntax Auto Spacing Eclipse - eclipse

In visual studio If I type:
int x=5*6+2*3;
It will automatically format it to:
int x = 5 * 6 + 2 * 3;
In eclipse I have to press CTRL+SHIFT+F to do this.
Is there any way I can make it happen automatically like in visual studio??
Thanks

Preferences → Java → Code Style → Formatter → Edit 'Active Profile' → White Spaces → Expressions → Operators (and the others)
Tick all desired boxes for white spaces, then Apply.
To inoke the formatter in the code editor, press CTRL + SHIFT + F (default).
You may also set the formatter to be invoked automatically on a Save Action, by going to Preferences → Java → Editor → Save Actions → And tick Format Source Code, along with other desired configurations of course.

Related

How do I change the linter/formatter in VS Code?

I'm on Ubuntu. Pushing Ctrl + Shift + i in VS Code auto formats the file.
I was editing a solidity contract and pushed Ctrl + Shift + i, VS Code didn't have a formatter configured so it asked me to pick one - I accidentally chose my JS prettifier extension instead of the solidity one. This badgered up my code by trying to use single quotes instead of double quotes (not allowed in solidity) and some other non-solidity friendly changes.
Pushing Ctrl + Shift + i now just auto formats with the wrong formatter with no option to pick a different one.
How can I change which linter/formatter is associated to which file types in VS Code?
Solution A:
Press Ctrl+Shift+P
Then type Format Document With...
At the end of the list click on Configure Default Formatter...
Now you can choose your favorite beautifier from the list.
Solution B:
go to file -> preferences -> settings search for format, on the left side, click on Text Editor, the very first item on the right side is Editor: Default Formatter from the dropdown you can pick any document formatter which you installed before.

Eclipse Shortcut Key for Color and Fonts -> Basic -> Text Font

I often change the font size of my editor. So does anyone know a shortcut key for that? Until now I have to use the menu with several clicks: Preferences -> Color and Fonts -> Basic -> Text Font. Would be nice of one can use CTRL + MouseWheel...
I am sure at some point of time you would have wanted to increase/decrease the font using CTRL + + or mouse scroll.
Found one solution, CTRL and +/- keys for increasing and decreasing font.
Download jar from
http://code.google.com/p/tarlog-plugins/downloads/list
Place the jar in plugins directory of eclipse installation
Restart eclipse.
Enjoy
You can get close by binding your-favorite-function-key to the command. Here's how:
Windows > Preferences > General > Keys
Locate the command related to setting the font >> Preferences (General > Appearance > Colors and Fonts)
Click inside the Binding text field
Specify the key-binding you wish to use by pressing the appropriate keys
Accept by pressing OK
Profit!
I'm using Aptana with an English keyboard and casually came into these keys combinations
- [CTRL] + [-] then 1 --> smaller font
- [CTRL] + [SHIFT] + [=] --> bigger font
NOTE:
[-] key is on the main keyboard, not the numeric pad
[SHIFT] + [=] gives + in the English keyboard

Eclipse editor show variable occurrence

In Eclipse Standard Installation the editor marks all occurrences of a variable if you click on it with a cursor.
e.g. Setting the cursor somewhere on the 'foo' Variables it highlights all other foo's too.
public void printString(String foo){
System.out.println(foo); }
Any ideas where to switch this behavior on again or why the feature doesn't work ?
I know the workaround is 'References->Workspace' but the auto highlighting is much more convenient.
You are asking about the "Toggle Mark Occurrences" the short cut for this is Alt + Shift + O
You can also enable it from
Window > Preferences > Java > Editor > Mark Occurrences

Expanding and creating code templates in Eclipse when using emacs keybindings

How do I expand code templates in Eclipse when using the emacs keybindings?
Is there a hotkey for turning selected code into a template?
Apparently for C/C++ you have to enable templates in Window -> Preferences-> C/C++ -> Editor -> Content-assist -> Advanced.
Uncheck everything except templates and check templates in both the upper and lower boxes.
Then in the editor type a template name like:
for
and hit Alt + / to expand it into:
for (var = 0; var < max; ++var) {
}
Use Tab to fill in the blanks.
NOTE: eclipse 3.5

How can I show line numbers in Eclipse?

How can I show line numbers by default in Eclipse?
Window → Preferences → General → Editors → Text Editors → Show line numbers.
Edit: I wrote this long ago but as #ArtOfWarfar and #voidstate mentioned you can now simply:
Right click the gutter and select "Show Line Numbers":
If this doesn't work it may be overridden by your current settings. You can right-click in the bar to the left of the code where line numbers would normally appear and turn them on with the context menu.
Update November 2015:
In Eclipse Mars 4.5.1, line numbers are (annoyingly) turned off by default again. Follow the below instructions to enable it.
Update December 2013:
Lars Vogel just published on his blog:
Line numbers are default in Eclipse SDK Luna (4.4) as of today
(December 10, 2013)
We conducted a user survey if users want to have line numbers activated in text editors in the Eclipse IDE by default.
The response was very clear:
YES : 80.07% (1852 responses)
NO : 19.93% (461 responses)
Total : 2313
Skipped: 15
With Bug 421313, Review - Line number should be activated by default, we enabled it for the Eclipse SDK build, I assume other Eclipse packages will follow.
Update August 2014
Line number default length is now 120 (instead of 80) for Eclipse Mars 4.5M1.
See "How to customize Eclipse's text editor code formating".
Original answer (March 2009)
To really have it by default, you can write a script which ensure, before launching eclipse, that:
[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.editors.prefs does contain:
lineNumberRuler=true
(with [workspace] being the root directory of your eclipse workspace)
Then eclipse will be opened with "line numbers shown 'by default' "
Otherwise, you can also type 'CTRL+1' and then "line", which will give you access to the command "Show line numbers"
(that will switch to option "show line numbers" in the text editors part of the option.
Or you can just type "numb" in Windows Preferences to access to the Text Editor part:
Picture from "How to display line numbers in Eclipse" of blog "Mkyong.com"
As simple as that.
Ctrl+F10, then N, to Show or hide line numbers.
Reference : http://www.shortcutworld.com/en/win/Eclipse.html
Slight variation on Mac OSX:
Eclipse → Preferences → General → Editors → Text Editors → Show line numbers
Windows → Preferences → General → Text Editors → Show numberlines
in this file
[workspace].metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.ui.editors.prefs
make sure the parameter
lineNumberColor=0,0,0
is NOT 255,255, 255, which is white
Go to Windows → Preferences → General → Text Editors → Show numberlines. Click OK, then Apply changes. Then it will show the line count automatically.
one of the easy way is using shortcuts like : Ctrl+F10, then press n "it show line number and hide line numbers.
The top answer is good but you can also bind it to a key ( shorcut ) to toggle it..
Window > Preferences > Keys then enter "Line Numbers" in filter and bind it to a key.
I use CTRL + S + L.
Open Eclipse
goto -> Windows -> Preferences -> Editor -> Text Editors -> Show Line No
Tick the Show Line No checkbox
click on window tab and click on preferences
do this and check show line number
the eclipse changes the perferences's position
to eclipse -> perferences
On a Mac do this:
cmd + , or ADT -> Preferences
Expand General -> Editors ->Text Editors
Check box: Show line numbers
Eclipse has a search feature in the top left box of the Preferences.
Type in 'line numbers' in that search box, and presto...
In case you're tired of googling each time you forget...
this will be the appropriate solution for asked question:
String lineNumbers =
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER;
EditorsUI.getPreferenceStore().setValue(lineNumbers, true);