Sysout shortcut key not working even after setting the template - eclipse

I added the sysout in the Eclipse template, context as Java statements and Pattern as System.out.println(${word_selection}${});${cursor} but still when I try typing "sysout" and press Ctrl + Space, it says "No default proposal".
Please help me how to figure this out, I am using MyEclipse version -8.6

I had the same problem, but it turned out I was typing a code snippet outside of a method, so Eclipse correctly decided not to propose this template. How silly!

Eclipse > Preferences > Java > Editor > Content Assistant > Advanced
Make sure Template Proposals is checked in one of the shown lists.

You shouldn't need to add the template as it should already be there under Java->Editor->Templates. Ensure that you have ticked the checkbox at the beginning of the template definition. Also make sure that you're pressing Ctrl+Space with the text cursor positioned immediately after the "t" in "sysout". This works for me.

In my case, I had the Apache POI library referenced in my project which added the SystemOutLogger to the list of things to insert.
'sysout' will only be auto inserted if it is the only thing in the
list.

Related

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

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/

Validate Autocomplete in Eclipse

Coming from Visual Studio and starting a project in Java, I realized I couldn't cope with having to press ctrl+space to have the autocomplete panel show up. An easy workaround was to set all keyboard characters to be trigger characters for autocompletion.
My only problem is that, when presented with autocomplete suggestions, a single press on the space bar will write the first proposition. In situations where I'm happy with the suggestions, that's just fine. In situations where I actually want to use what I wrote down initially, I have to press 'escape' first to remove the autocomplete panel before I can press 'space' safely.
Netbeans doesn't use the space bar as a validating key for autocompletion (only 'enter' does that) and I like that behavior. Any way to replicate it in Eclipse?
Thanks in advance for your answers!
EDIT: I should have mentioned I'm using Eclipse on the Mac.
Guillaume
I have the same problem with Eclipse Indigo on Windows XP actually. Coming from intellij idea, I also felt the need to set the whole keyboard to trigger auto-complete.
A quick proof that SPACE key does accept suggestions : type inte on a new line. If the auto-complete menu shows, press SPACE. It goes for Integer.
If anyone knows how to set the SPACE key to "ignore suggestions", it would be great, because the escape key on my keyboard is also too far away :)
Thanks
Edit : actually the best would be to have only the ENTER key validating, because ';' and '(' also seem to validate
I just tried to reproduce your behavior, but couldn't. Here is the configuration I have (and the steps I have done to reproduce):
I have installed Indigo (current version of Eclipse, version number 3.7).
I did not change any configuration there, this is what is the default:
Under Window > Preferences > Java > Editor > Content Assist, I have the following settings:
Completion inserts (instead of overwrite)
Insert single proposal automatically (which is ok most of the time)
not insert common prefix automatically
I have a simple class, go down to a method, and do the following steps:
Enter this.no and wait some time. Sometimes I have to press CTRL + SPACE, sometimes not.
Proposal pops up which includes notify and notifyAll.
I press SPACE and a space is inserted in the text, the autocomplete suggestions are closed without inserting anything.
I do not know if older versions of eclipse have the same behavior.

Eclipse highlighting the same occurrence of the word

In Notepad++, it has a very nice feature that if I select a word, it will highlight all the same words throughout the text. I can also set the hot-keys to highlight up to five different words with different styles (See the effect below) .
Is there any ways to get this similar effect in eclipse? I know when editing Java, it will highlight all the same variables, but it will not work when I highlight the comments and editing other files type (e.g. xml, html, js, css and etc).
I've been working with Eclipse for quite a while and I'm pretty certain that there is no canonical way of doing this.
In Eclipse these things are managed on a per-editor basis and the Java editor does not support what your looking for for all I know. At least for the Java editor you can do some minor configuration in what is highlighted and how (Preferences > Java > Editor > Mark Occurrences), but I guess you already know that.
As for plugins, I'm not aware of any plugin that achieves what you're looking for. As a matter of fact I'd be surprised if there really was a plugin which achieves what you're looking for.
If something comes up I'd much appreciate you sharing it here, I've been trying to get decent highlighting into Eclipse for years unsuccessfully... :)
Here is a plugin for eclipse: http://ystrot.github.io/glance/
It highlights all occurrences as with notepad++ upon hitting Ctrl + Alt + F.
Below is what I found works for me but you can also assign a key shortcut to 'Find Text in File':
Select the word or section of text
Press CTR+3 to activate 'Quick Access' search
Type 'Find Text in File'
Execute
As mentioned by #Kislingk you can modify how the words are highlighted/marked in 'Preferences > General >Editors>Text Editors > Annotations'.
Here is the closest solution I have found:
Create a shortcut in Preferences/General/Keys
type in the search field: "Find Text in File"
By default it has nothing assigned so just assign your key binding to it.
Annotations can help with displaying it in the sidebar
If you enable "Mark Occurrences" (Alt + Shift + O), then all words that are the same as the one you have marked will be highlighted.
Well if you're searching in the currently open file only (via CTRL-F) then no, you can't have everything highlighted.
However if you use the advanced search (CTRL-H, then go to "File search" tab) there you can input the search pattern, as well as the file-name pattern for the file(s) where it should search, and when the search is done, the search terms are highlighted in each file where they were found:
Use file search to search selected resource can highlight same word in single file.
Another useful eclipse plugin is eclipse instasearch. It has extensive feature set. This is also available in eclipse marketplace.
There are other options needed to enable.(Preferences > General >Editors>Text Editors > Annotations). Find Occurrences and WriteOccurrences and enable Text as 'Hightlight'
Have tried all of the above answer, but all not working. At the end, i found that it's due to i have accidentally remove some of the JRE System Library, after add back, it's work correctly
Window > Preferences > Java > Editor > Mark Occurrences

Javadoc Tooltip with Content Assist in Eclipse

When i started to use Eclipse's Content Assist, Eclipse used to give me Javadoc help of item i focus in a tooltip box next to content assist. However, after a while Javadoc tooltip stopped working. I tried resetting preferences to default but no luck. What should i do?
p.s: Javadoc works when i highlight an element (i.e. a method).
I mingled with various options for 4 hours...even created a new workspace. Finally what worked for me was some preference changes.
Goto Preferences > Java > Editor > Content Assist, click on Restore Defaults.
Restart Eclipse and you are good to go.
You could try checking you have the latest version (and possibly reinstalling) xulrunner. That's Mozilla's platform independent GUI library, and as far as I'm aware it's used to display the javadoc, both content assist popups and in the javadoc tab. The likely cause of your problem is bugs/communication difficulties between eclipse and xulrunner.
I was facing the same problem here, and then, armed with Gaurav Kumar tip, I managed to solve it.
The problem here was that I had put a lower auto activation delay value. When I put it back to 200 and restarted Eclipse, the javadocs came back.
I solved the problem by changing Preferences > Java > Editor > Content Assist -> Auto Activation -> Auto activation triggers for Javadoc from "##" to "#".

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