How can I keep Eclipse from filling in auto-completions when I type an opening parenthesis ('(')? - eclipse

So, on Eclipse Luna, I often encounter the situation where I'm typing a method name, but the first autocomplete suggestion is not the method I am looking for but something that is prefix-equivalent but longer, as in this example:
In the example, I just wanted the element(String name) method, so instead of hitting Return, I type ( instead. The result, quite annoyingly, is this:
This is clearly not what I was looking for. Is there a way to prevent Eclipse from performing auto-complete when I hit open-parenthesis (()?
These are my content assist settings (aparrently, I don't have code recommenders installed at all in this eclipse installation):

In Eclipse 4.11 (2019-03), and possibly earlier, the answer to this is under Preferences → Java → Editor → Content Assist → Disable insertion triggers except 'Enter'. After I checked that box, editing became a lot less annoying.
I have no idea why Eclipse doesn't do it by default. Who types map.put( and wants that to autocomplete to map.compute()?

A hack for this is to change the way Eclipse sorts the proposals.
You can go to Preferences menu and then go to the section for which you want to edit sorting. Then to de Editor section and Content Assist.
For example, for Java editor, it will be Preferences > Java > Editor > Content Assist.
There you will see, more or less in the middle of the window, a section called Sorting and filtering. Inside there is an option called Sort proposalswhich you can change from by relevance to alphabetically. Save an close.
With this you will get the proposals list order alphabetically and element() will be before other methods starting by element.
EDIT:
Tested in Eclipse Luna running in Ubuntu 14.04 and it works. You'll still get your code completed when writing ( but it will be completed with the shorter option available in the proposals list. If you want to use another method, you can continue writing some letters and the shortest option will disapear of proposals as it doesn't match what you are writing.

I guess your problem is the substring matches.
Go Window->Preferences->Java->Editor>Content Assist.
In Sort proposals section uncheck Show substring matches.
I found By relevance more useful then Alphabetically.
I have usually checked hidden Hide proposals not visible in the invocation target, and Hide deprecated references, too.
I hope it help.

The feature you're fighting with is the new "Intelligent code completion" which orders methods based on average usage count. Don't ask me where they get the data. See also here:
http://www.eclipse.org/recommenders/manual/#intelligent-code-completion
To disable the feature go to the preferences page Code Recommenders|Completions and uncheck "Enable intelligent code completion".

Another issue which might negatively affect code completions appears to be 'Java Proposals (Task-Focused)'. For example, it causes map.put() to be replaced with map.compute().
You can disable these from Preferences | Java | Editor | Content Assist | Advanced.
See also: http://literatejava.com/eclipse/bad-auto-completions-in-eclipse/

Related

How to change eclipse suggestions order and content

I installed the Eclipse Neon but feels bad with its code suggestions.
Take the code template as an example, usually I type main and press <ALT> + / to show the suggestions. In the old versions, the main method template shows at the first one. However, the top N is occupied by many Main* class main, it doesn't make sense for me.
Is there any way to change it ?
how to remove any Main* class's suggestions
how to let the code template move to top
Not exactly what you need, but the most approximate solution I know is that you can press CTRL+SPACE repeatedly to browse the content assist list. The first list Eclipse shows is the default proposals. But if you press CTRL+SPACE again and again, Eclipse will show a more specific list each time.
Go to Window > Preferences > Java > Editor > Content assist > Advanced.
The upper list allows you to select (not to sort, sorry!) the contents that will show up as default proposals. This is where you read this unordered, unpractical list of contents. Then, if you press CTRL+SPACE again, Eclipse will show the poposals by categories. The order for these categories to show can be set by the lower list in this window: Content assist cycling.
Don't know if this will be relevant any more, but i ended up here looking exactly for this, and later found out a solution. This might be linked to a specific Eclipse version (i use Oxygen right now)
Go to Window > Preferences > Java > Editor > Content assist and you will find an option that let you select between relevance and alphabetically.

Eclipse content assist auto appends type for variable

I just started to use Juno for a couple of days, the content assist mechanism seems different from what it behaves before.
For example, if I try to declare a variable
Boolean isVisible
The content assist of Juno will give you a drop-down list with the variable name
isVisibleBoolean
as hint.
And the very annoying thing is that no matter what I typed in(; or SPACE), the "isVisibleBoolean" will be selected.
Does anybody know how can I disable the auto-variable-type-appending thing?
Much appreciated.
I'm using Mac OS X 10.8.1 currently, haven't tested it yet in windows.
Based on the discussion for Eclipse Bug 412992, check your Content Assist Auto Activation settings:
Window->Preferences->Java->Editor->Content Assist
If, for example, characters a-z are listed as "Auto activation triggers for Java", you can remove them and the type name will not be auto-appended to a new variable name when you hit ' ' or ';'. It's up to you to determine the best configuration/tradeoffs for your style based on the available options.
It seems that it is not possible.
See answers to Eclipse Bug 378588: https://bugs.eclipse.org/bugs/show_bug.cgi?id=378588
This is still a problem in Eclipse 2018-12 and it only seems to occur if you changed the Auto activation triggers for Java setting to e.g. ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, which'll make the Content Assist (almost) always pop up, even without pressing Ctrl+Space (Windows).
There's a new setting that was added in Eclipse 2018-12 and makes it a bit less annoying (mentioned in the comments below the bug report):
In Window - Preferences - Java - Editor - Content Assist tick the Disable insertion triggers except 'Enter' box.
With this setting enabled, Content Assist is still going to trigger (depending on the other settings) but you have to press Enter to accept a suggestion.
Not a perfect solution:
Window->Preference->Java->Editor->Content Assist->Auto activation Triggers for Java: .ABCDEFGHIJKLMNOPQRSTUVWXYZ
In this way, only classes and types will be popped up for proposals.
Just a suggestion, the choice is up to you.
What you see there is name completion for object types. And this may often make sense, e.g. pressing Ctrl-Space after List book will complete that to List bookList. For primitive types this is not done, so int count will not get any completion when pressing Ctrl-Space. This would be a (not really good) solution to your problem by declaring the variable as primitve boolean.
What I really recommend as solution is to change your style of writing variable declarations. For your example, write isVisible = false instead, have the editor complain about the missing type declaration, hit Ctrl-1 (from wherever your cursor might be placed), Enter.

Variable use highlighting in Intellij IDEA

One of the features I really like about Netbeans is that when you click on a variable, method, field etc. Netbeans shows you all the usages of this entity in the right hand bar as little bars of colour. Is there a way to get this behaviour in IntelliJ IDEA and if so, how do I turn it on? I haven't found anything in the settings or Google but I might be missing something!
file>settings or ctrl+alt+s (for windows) select editor from the list on the left and check Highlight usages of element at caret in the Highlight on Caret Movement section
Apart from enabling the "automatic highlight usages" setting described above, you can also invoke "highlight usages" manually, using the shortcut Ctrl+Shift+F7.
The benefits of using the "manual" highlight usages are:
You can highlight usages of multiple variables/methods/etc at the same time
You can remove highlighting for an individual element selectively, by invoking Ctrl+Shift+F7 again on that element
some users find it less distracting than "automatic highlight usage" - this is subjective or course
Above answers are correct but still to get the exact behavior like in Netbeans try to use Identyfier Highlighter plugin for Intellij Idea (available in default plugin list under window settings).
This is really strange as Idea features mentioned in previous answers would do the job if merged into the one configurable feature.

How to replace Eclipse search dialog?

Is it possible to replace Eclipse search dialog to something more convenient, like the search dialog in Firefox or Chrome? The default one doesn't support F3 to search for the next match, it doesn't move itself away if the match is underneath the box and doesn't allow to highlight all the matches - and these are the features I really miss...
I don't think you can replace the Find dialog easily. You would probable need to (re-)write parts of Eclipse. Definitely doable, but not a small task...
That said, most of your problems can probably be addressed by the current dialog:
The default one doesn't support F3 to search for the next match
"search next match" is Ctrl-K by default. You can configure the keybindings under "Preferences / General / Keys": change the keybinding for "Find Next".
it doesn't move itself away if the match is underneath the box
Yes, that would be nifty. The dialog does however remember where you last put it, so just put it somewhere out of the way (e.g. over the package browser, or to the right), and it will stay there.
and doesn't allow to highlight all the matches
This is not yet available (though it has been discussed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=29692 ). There are however two ways of getting a similar result:
Use the search function from the toolbar ("File Search" from the "torch" button). If you search there, it will highlight all matches in the editor (and provide marks in the editor ruler, and a list in the search view).
For Java elements, activate "Mark Occurences" ("highlight pen" button). This will highlight all occurences of a Java element if you mark in in the editor.
Maybe one of these will help you.
Finally, you can just open any file in an external editor (like (g)vim or Notepad++) right from inside Eclipse (right-click -> Open with). Then you can use any editor you want...
While it may not be exactely what you want, have you ever used the incremental search (Ctrl + J)? In my opinion it is much more convenient than the standard search.
A newer alternative is InstaSearch.
Information:
InstaSearch is an Eclipse plug-in for doing fast text search in the workspace. The search is performed instantly as-you-type and resulting files are displayed in an Eclipse view. It is a lightweight plug-in based on Apache Lucene search engine.
Each file then can be previewed using few most matching and relevant lines. A double-click on the match leads to the matching line in the file.
The "search the next match" is Ctrl-K. Previous is also available, see the "Edit" menu...
Only the highlight feature does not seem to be present. You might need a plugin for that (everythinhg is possible with plugins).
There was a Summer of Code project to implement a Firefox like search in Eclipse in 2007.
This is the official page, and this Blog shows a promising screenshot.
I never tried to install it, and I didn't find a final release or something though :(
SearchTab is an Eclipse plugin that shows a Firefox-like search tab
You do this by changing the key bindings under Preferences -> General -> Keys

Useful Eclipse features? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have been using Eclipse as an IDE for a short amount of time (about 3 months of full use) and almost every day I learn about some shortcut or feature that I had absolutely no idea about. For instance, just today I learned that Ctrl+3 was the shortcut for a Quick Access window.
I was wondering what your most useful/favorite Eclipse features are. With the IDE being so big, it would be helpful to learn about the more commonly used parts of the program.
My most commonly used features are
ctrl+1 quick-fix / spell-checker
opening files
ctrl+shift+t load class file by classname
ctrl+shift+r load any file by filename
matches are made on the start of the class/filename. start your search pattern with a * to search anywhere within the filename/classname.
Formatting
ctrl+shift+f Format source file
(set up your formatting style in Window | preferences | java | code style | formatter)
ctrl+shift+o Organise imports
Generated code
alt+s,r to generate getters and setters
alt+s,v to insert method signatures for overidden methods from superclass or interface
Refactorings
alt+shift+l Extract text-selection as local variable (really handy in that it determines and inserts the type for you.
alt+shift+m Extract text-selection as a method
alt+shift+i inline selected method
Running and debugging.
alt+shift+x is a really handy prefix to run stuff in your current file.
alt+shift+x, t run unit tests in current file
alt+shift+x, j run main in current file
alt+shift+x, r run on server
There are more. The options are shown to you in the lower-right popup after hitting alt+shift+x.
alt+shift+x can be switched for alt+shift+d in all the above examples to run in the debugger.
Validation
As of the recent Ganymede release, you can now switch of validation in specified files and folders. I've been waiting for this feature for ages.
Go to Project | Properties | Validation
click on the ... button in the settings column of the validator you want to shut up
Add a rule to the exclude group
code navigation
hold down ctrl to make all variables, methods and classnames hyperlinks to their definitions.
alt+left to navigate back to where you clicked ctrl
alt+right to go "forwards" again
This is cool: If someone has emailed you a stack trace, you can copy and paste the stack trace into Eclipse's Console window. You can then click on class names in the stack trace as if your own code had generated it.
In terms of actual features, rather than shortcuts, I strongly recommend taking a look at Mylyn.
It essentially skins Eclipse with a task focussed view. It tracks the files you touch when working on a task, and focusses many aspects of the UI onto the resources that it decides are relevant to the job in hand. Eclipse can be somewhat busy to look at, especially with a big multi module project, and Mylyn helps cut through the cruft. The connectivity to issue tracking software and source control repositories is also excellent.
In my experience, it polarises opinion amongst those who try working with it, which is probably a sign that it is offering something interesting... Don't mean to sound like a fanboy - it is definitely worth a look though.
A shortcut that I use everyday is Ctrl+K. In your editor (not only Java file), simply select a text (like a variable, a function, etc.), and then use this shortcut to go to the next occurrence of this text in the current editor.
It's faster than using the Ctrl+F shortcut...
Note also that you can use Ctrl+Shift+K to search backwards.
Ctrl-Alt (up/down) Copy selected line(s) above or below current line.
Alt (up/down) Move current (or multiple selected) lines up or down
Ctrl-Shift-R Bring up the resource window, start typing to find class/resource
Ctrl-O Bring up all methods and fields for the current class. Hitting it again will bring up all methods and fields for current class and super classes.
Ctrl-/ or Ctrl-Alt-C Comment single or multiple lines with //
Ctrl-Shift-/ Comment selected lines with /* */
Ctrl-. Take you to the next error or warning line
CTRL+PAGE DOWN / CTRL+PAGE UP to switch between opened editors
CTRL+E to also switch between opened editors (allows to type the name)
CTRL+O is extremely important for me. You don't longer need the Outline View then (you can close it which will give you more space). Then, you can type a method name or just the beginning of it and you quickly can get to it. I also use it to inspect what stuff is available. For example: CTRL+O and then type get ... now I see all getters.
F3 while an element is selected in the code: brings you to its definition or it's source. e.g. used on a method call it brings you into the source code of that method.
CTRL+M to maximize the current window
As already said, CTRL+3 is extremely good. It basically allows you to use Eclipse completely without a mouse. Just type CTRL+3 and then package explorer for example.
CTRL+F8 cycle trough perspectives
CTRL+L allows to type a line number and brings you directly to that line.
CTRL+SHIFT+G searches for all references to the selected element in the workspace.
And not a shortcut: In the project settings under Java Editor you can find Save Actions. This allows you to set up the project so that the code is automatically cleaned up and formatted when you save a file. That's very good it safes you from constantly pressing CTRL+O and CTRL+F.
Eclipse auto refresh isn't on by default so if you make changes to a file outside of eclipse, the change won't be reflected in your build. this is very annoying if you just did an svn/git update/rebase and things aren't working the way they're supposed to.
Turn it on in windows->preferences->workspace and tick Refresh Automatically.
Local History
It's a great feature. Eclipse has its own mini-CVS for all files in a project. If you want to revert some change you made, or even restore deleted file - you can right click on the project and select "Restore from Local History".
Just saved my ass *tears of joy*
CTRL+Shift+P to jump to the matching bracket/parenthesis.
One key feature: Shift+Alt+T for the refactoring menu.
Ctrl-shift-T, but only type the initial characters (and even a few
more) of the class you're looking
for. For example, you can type
"NetLi" to find NetworkListener
In the Search window, Ctrl-. takes you to the first leaf of a tree branch
Alt-/ is Word Completion. Slightly different from Ctrl-space
CTRL+SHIFT+X selected text becomes UPPERCASE
CTRL+SHIFT+Y selected text becomes lowercase
I'd like to add two additional shortcuts:
CTRL+F6 Switch between open editors (CTRL+SHIFT+F6 to scroll through the list in the opposite direction)
CTRL+F11 start program in debug mode
F11 start program in normal mode
A lot of the key bindings depend on the perspective and view currently active.
My most used ones for the Java perspective:
ctrl-shift-r open resource
ctrl-shift-t open type
ctrl-1 quick fix/refactor
ctrl-j incremental search
ctrl-h search in files (select a base directory and set scope to selected resources)
ctrl-o list methods
ctrl-alt-h open call hierarchy
ctrl-shift-l list shortcut keys
hit ctrl-shift-l again to go directly to preferences to change key mappings
I am also a fan of Eclipse, however since I spend a majority of my time in Visual Studio, I will suggest that you read Eric Sink's series of articles "C# to Java" (parts 1-4). Not only is Eric always an entertaining read, but this brief series covers some awesome Eclipse insight for those who have not been into Eclipse or have been away from it for a while:
From C# to Java: Part 1
From C# to Java: Part 2
From C# to Java: Part 3
From C# to Java: Part 4
Ctrl-Shift-M while the cursor is on a class name in your java file, will specifically add that and only that class to your imports. This is different from Ctrl-Shift-O which will not only add those imports not already defined, but will also remove imports not currently needed, something you might not necessarily want to do.
I forgot about [Ctrl+2 -> r] scope variable rename. Place the cursor in the variable you wish to rename, press Ctrl+2, then r, then type the new name watching all instances of that variable get renamed at the same time.
It's awesome at refactoring Hungarian Notation.
alt-shift-a is extremely useful in a few situations.
I use a lot of the above and also like for quick search: CTRL+J then type what I am looking for, then CTRL+K for next occurrence.
Lately I've been using the MouseFeeds plugin to automatically tell me what the key stroke combinations are. That way by repetition I remember them better.
This link has a better picture and description of what it looks like and does.
Shift+Alt+b for the simple navigation row over the editor.
I've just released this blog post about Top 5 Useful Hidden Eclipse Features. It contains:
Favorites: Types and members that will always show up in auto-completion
The awesome block selection mode: For multi-line editing
The EGit staging view: Much better than git itself
Type filters: To remove awt and java.lang.Object stuff from auto-completion
Formatter tags: To delimit code sections that shouldn't be auto-formatted
Alt+left and Alt+ right will navigate you forward and back.
I find the project-specific settings useful in Eclipse 3.3.
For example, if you have several developers working on a project who have different code styles for curly braces, line spacing, number of imports etc. then you can specify the style settings for the project. Then you can configure the save actions so that the code is automatically formatted when a file is saved. The result is everyone's code is formatted the same before it's checked in.