What is the Auto-Alignment Shortcut Key in Eclipse? - eclipse

What is the auto-alignment shortcut key in Eclipse?

Ctrl+Shift+F to invoke the Auto Formatter
Ctrl+I to indent the selected part (or all) of you code.

Auto-alignment? Lawful good?
If you mean formatting, then Ctrl+Shift+F.

The answer that the OP accepted is wildly different from the question I thought was asked. I thought the OP wanted a way to auto-align = signs or + signs, similar to the tabularize plugin for vim.
For this task, I found the Columns4Eclipse plugin to be just what I needed.

Want to format it automatically when you save the file???
then Goto
Window > Preferences > Java > Editor > Save Actions
and configure your save actions.
Along with saving,
you can format, Organize imports,add modifier ‘final’ where possible etc

auto-alignment shortcut key Ctrl+Shift+F
to change the shortcut keys Goto Window > Preferences > Java > Editor > Save Actions

Related

Cmd+I does not work in Java Perspective in Eclipse?

I'm using Eclipse 4.4.1 on Mac OS X 10.10.2. Menu File > Properties has a hotkey Cmd+I. But pressing that does not bring up the same window showing the properties of the .java file open in the editor window. Any ideas?
BTW, do people have a sense if SO is any better than than https://eclipse.org/forums/ for getting quick replies?
In the Java editor Cmd+I is bound to the 'Correct Indentation' command, this takes precedence over the Properties binding when you are in the editor.
Look in 'Preferences > General > Keys' to see the key bindings. Click on the 'Binding' column to sort by the key binding to see all the bindings for a key together.

Control-M -> ENTER in Eclipse

Is it possible in Eclipse to assign Control-M key to newline?
Windows XP + Helios.
I don't know for sure, not having done it myself, but investigate the key binding dialog Window > Preferences > General > Keys. See page 362 of the 3.1 documentation for more.
In Window > Preferences > General > Keys,
redefine Insert new line Below current line, and Bind Ctrl+M.
Be careful, by default, Control-M already toggles maximize/restore state of active view or editor. this will override the shortcut.

How to remove unused imports from Eclipse

Is there any way to automatically remove all unused imports (signaled with a warning) of a project with Eclipse IDE?
I just found the way. Right click on the desired package then Source -> Organize Imports.
Shortcut keys:
Windows: Ctrl + Shift + O
Mac: Cmd + Shift + O
You can direct use the shortcut by pressing Ctrl+Shift+O
I know this is a very old thread. I found this way very helpful for me:
Go to Window → Preferences → Java → Editor → Save Actions.
Check the option "Perform the selected actions on save".
Check the option "Organize imports".
Now every time you save your classes, eclipse will take care of removing the unused imports.
Remove all unused import in eclipse:
Right click on the desired package then Source->Organize Imports.
Or
You can direct use the shortcut by pressing Ctrl+Shift+O
Work perfectly.
If you want to do this on whole project then inside project -->select src folder-->press Ctrl+Shift+O
Use ALT + CTRL + O. It will organize all the imports. You can find various other options in the "Code" Menu.
EDIT: Sorry it is CTRL + SHIFT + O
Better way is just to add "save action" so when you save the project it will clear the unused import's and format the code as well if you like .
Go to Window > Preferences > Java > Editor > Save Actions
and pick what ever you want .
press Ctrl+Shift+O and it will remove unwanted imports
Certainly in Eclipse indigo, a yellow line appears under unused imports. If you hover over that, there will be multiple links; one of which will say "Remove unused import". Click that.
If you have multiple unused imports, just hover over one and there will be a link that allows you to remove all unused imports at once. I can't remember the exact wording off hand, but all the links that appear are pretty self explanatory.
Not to reorganize imports (not to unfold .* and not to reorder lines) to have least VCS changeset
you can use custom eclipse clenup as this answer suggests

How to modify the keyboard shortcuts in Eclipse IDE?

Title more or less says it all. Specifically, I've become increasingly annoyed that in order to run an ant script I have to use Alt+Shift+x, q. But I think If I had this power I would many things I would change the shortcuts for/add shortcuts for things that don't currently have them.
Window > Preferences > General > Keys
In particular, edit the "Run Ant Build" command.
For Windows:
Window > Preferences > General > Keys
For mac that would be
Eclipse > Preferences > General > Keys
Pressing Ctrl + Shift + L will open the current list of defined shortcuts, again pressing Ctrl + Shift + L will open preference page from where the shortcuts can be modified.
As a side note make sure your newly mapped Shortcut won't have any conflicts on the right of the Keys window/menu.
If so choose a combination that will work; doesn't have any conflicts with existing ( default ) settings.
Hope this helps.

How to highlight the selection in Emacs keybinding of Eclipse?

I have searched the Web for this, but with no luck. Any idea?
Thanks.
Try using the Emacs+ plugin available here:
http://www.mulgasoft.com/emacsplus
It provides a HUGE range of functionality - including the selection highlighting that you're looking for - that really helps the move from Emacs. I've only been using it for a couple of days, but it appears stable and integrates very well with the editor.
As described here, you can set emacs key binding to work in component editor in Eclipse
Go to Preferences -> General -> Keys.
Change Scheme to Emacs if you haven't done so already, so you can easily
spot the emacs key bindings.
Sort by Category and look at the "Text Editing" categories
Find the commands that you care about, e.g. Next Column, Previous Column
Select that command and click "Copy Command"
Set the binding to the key by pressing the keys, e.g. press Control-f to
generate "^F".
Change "When:" to "Editing Components".
Repeat for all the key bindings you care about.
So if, in emacs, selection is done by setting the mark (Control-Space) at the start of the region, then moving the point to to the end of the region, you could associate the appropriate shortcut to:
Text Editing > Select Text Start
Text Editing > Select Text End