Partial AutoComplete in eclipse? - eclipse

I'm very happy with the way eclipse autocompletes for me, but I was wondering if it could do something more...
I often have very similarly named variables, such as myPlayerManagerPane and myCharacterManagerPane, I was wondering if there was a way that would allow me to get half way into the name, type a character or two and then autocomplete. This would let me copy and past lines of code for both, then surgically edit the variable names. It's gotten to the point where I'm trying to do this (I'm autocompleting on autopilot) and getting fun variables such as myCharacterManagerPaneManagerPane as I autocomplete a whole name, halfway through another.
Is there a way around this?

In Window > Preferences > Java > Editor > Content Assist, select "Completion overwrites", instead of "Completion inserts". This would overwrite the entire variable with the new one.
Alternatively, you can press Ctrl to toggle this behaviour when the content assist window pops up.

Your question (or rather, its prelude) can easily be confused with another one; namely,
Say I have two variables variableLabel and variableConfiguration, how can I have Eclipse complete the common prefix of the two variables, i.e. variable, before writing either L or C and having Eclipse "AutoComplete" complete the rest?
This is the question which lead me to this thread, so I feel I must answer it:
In Window > Preferences > Java > Editor > Content Assist, check "Insert common prefixes automatically". Pressing Ctrl+Space now results in the desired functionality.
Relevant StackOverflow question

Related

How do I modify the EL opening template in Eclipse?

Whenever I am working in a JSP file and I type ${ to start an el (Expression Language) tag, Eclipse will automatically add } (with a space before the closing brace) after the cursor so that I get ${ } instead of ${}.
Is there a code template in Preferences that I can modify to change this behavior, or is it beyond user preference control?
I have checked in Preferences: Web: JSP Files: Editor: Templates, but none of those templates match. I've also looked in several other sections in Preferences but haven't found anything promising.
What #Mero provided (see comments on answer above) might not be an exact answer, but creating a JSP Template probably the closest thing that I've found.
A few notes for anyone that wants to go that route:
Create a new template through menu Window->Preferences, then in the drill down menu navigate to Web->JSP Files->Editor->Templates. Click New.
Name is a shortcut you can type (the same way typing sysout ctrl+space in Java is a shortcut for System.out.println()). I suggest something simple like el. This allows you to type e l ctrl-space instead of $ { ctrl-space to pull it up.
Context tells it when it should appear in intellisense. I suggest creating two of this template where one has a context of JSP Attribute value and the other has a context of All JSP.
Description is just informative. Put whatever you want. I put 'EL Script' myself.
Pattern is where you put what will be inserted. Put $${${cursor}} or $${${script}}, depending on preference. See below for explanation on the differences.
In Eclipse Templates ${} is how you put variables in the template, so to make it actually print ${} you have to escape the $ with a $$ leading to $${}.
The predefined variable ${cursor} defines where the cursor is after intellisense replaces the el, so to have the cursor appear in between the curly braces you want to do this: $${${cursor}}.
Using any variable that is not predefined (in this case, ${script}) will simply put in that variable with a box around it and allow you to type over it and press enter when you're done, allowing you to move to the end of the closing curly brace.
Note: I understand that this is not an actual answer, but rather is a workaround. I'm putting it here simply so that those who are fine with a workaround can know how to go about doing it.
Edit
For those that don't like having to type ctrl-space, a workaround could be to have the template name start with< since on JSP pages, the < opens the intellisense, so for instance, you could have the name be <el or <$.
A workaround but not an answer:
Disable auto-close of EL tags. You type ${expression} and get ${expression}|, rather than typing ${expression and getting ${expression| }. (| denotes the cursor location)
See this answer, from when this same question was asked of Eclipse Kepler: https://stackoverflow.com/a/20258401/1021426

Disable line breaks after loops without body

Consider a Java while-loop without a body, for example this:
while (map.values().remove(value));
When formatting it (Shift + Alt + F), Eclipse breaks the line before the semicolon and indents it:
while (map.values().remove(value))
;
How can I configure the formatter to not add these line breaks?
Be aware that by setting this semicolon to a new line, you may avoid unintended endless loops and a long search to find them.
However, in Eclipse all code formatting properties are 1) in the project properties and 2) in the Eclipse properties. The project properties inherit from the Eclipse properties.
So if you open the project properties, type "format" in the search field. It will show you a "Formatter" menu item, that may depend on the current language (at least in Java it is called "Formatter"). Then, in this example, allow the project-specific settings, and then click edit. You will see a flood of possible details you can decide.
See here:
Then, in the tab "New Lines", uncheck the checkbox "Put empty statement on new line", in the section "Empty statements".
Often you have to try and search a bit because there are really many options. The part at right shows you a preview of the code formatting.

Is there a good "find all" function in Eclipse?

I have been using Eclipse for R and C++. So far I have not been able to find a reliable "find all" function. It seems to be an easy concept, I search for a string such as "rows" and the function should return all occurences of it within the that I currently have open. (Even if it's in all files in my owrkspace, that's fine too.)
However, I have either not understood how to use the "search" functions correctly or they are very buggy.
So my question is how do I search for all occurences of a string in a file in Eclpise?
Adobe Dreamweaver, for example, has been able to do this for years.(Although it's completely unrelated to R and C++)
I would like to view a list of all occurences and then be able to click on a specific occurence to go to it.
After opening Eclipse, (corresponding to a workspace), Press "CTRL + H" anywhere and you can search anything
like java files that contain specific "keywords".
all occurences within a java file.
plugins names etc
Just type "rows" or whatever the search term is somewhere in text, select it (so that it becomes highlighted) then press "Alt+Ctrl+g". This will perform a global search for that term, pretty handy.

Configure Eclipse word-boundaries so 'Next-Word-Key' skips whole identifier

If I have a piece of Code
MyIdentifierIsNice(OtherThingAlsoNice isBetterThen);
I'd like to change the behavior of Ctrl-Left in Eclipse from stopping here:
My|Identifier|Is|Nice|(|Other|Thing|Also|Nice is|Better|Then|);|
to here:
MyIdentifierIsNice(|OtherThingAlsoNice |isBetterThen);|
...or at least just not so often. Other variants would be also fine, like:
MyIdentifierIsNice|(|OtherThingAlsoNice| isBetterThen|);|
Mainly it should stop considering a CamelCaseIdentifier to consist of several words for navigation via Next-Word, and such like.
I use SpringSourceSuite Version 2.5.1, which is Eclipse 3.6, I guess.
Try and unselect the option:
Preferences / Java / Editor / Smart caret positioning in Java names
And see if that enhances the user experience in term of cursor positioning.
If this is not Java, you have a similar option in:
Preferences / General / Editors / Text Editors / Smart caret positioning at line start and end
It is usually selected, meaning if the cursor still stops at every word, that may suggests another setting for a specific language is overriding it.
Coming to Eclipse from XCode, I found the default navigation annoying. In Eclipse, Alt+Left and Alt+Right move to the next camelcase segment, and Ctrl+Left/Right does nothing. In XCode, Alt+Left/Right moves between words and Ctrl+Left/Right moves between camelcase segments. This allows you to control how fine-grained your navigation is.
How I fixed this for myself was by going into Preferences > General > Keys, searching for "Word", and changing the "Next Word" and "Previous Word" bindings from Alt+Left/Right to Ctrl+Left/Right. Then the Alt-navigation is by word and the Ctrl-navigation is by camelcase segment, as in XCode.
I thought this might be useful to some.
Edit:
As I continue to use these new settings, I've found another point:
Although navigation works as advertised, selection has some funky behavior. Namely, Shift+Ctrl+Left/Right can sometimes select large blocks of text instead of just the next camelcase component.
To fix this, again go to Preferences > General > Keys, search for "Select".
Set "Select Next/Previous Word" to Shift+Ctrl+Right/Left.
Unbind "Select Next/Previous Element" (there are three "Whens" to pick from, I unbound all 3).
Voila.
If you want a very simple way to select a entire word without the need to disable smart caret positioning.
You can use at the beginning of word or inside the word:
Shift+Alt+Right
At the end or in the middle of word:
Shift+Alt+Left

Custom key actions in Eclipse

Today I have question about Eclipse. I use this IDE very long and I think it is good, but last time I miss for some functionalities...
Is it possible to set some shortcut which will do something like:
Mark some text ('Hello world'), trigger shortcut (Ctrl+T) and it will do something with that text - in example adds text before and after selected text ($this->_('Hello world'))
?
Thanks for any sugestion !
From this, it appears you have to implement your own command in a plugin. The process looks more involved than simply setting a menu choice.
Equivalent functionality can be defined without commands, if you're willing to give up the keyboard shortcut and use content assist instead.
I'm not sure if it will work with the language you're using (PHP?), but with Java in Eclipse it is possible to use Code Templates.
You would define your own template, when it was applicable and what it would do. This could then be accessed with Ctrl+Space through the possible content assist methods. So in the context of Java statements, I can define:
this.call(${word_selection});
So when I highlight a word, such as "Hello, world", I can use the template to change it to:
this.call("Hello, world");
(There are ways to limit it to only String types instead of word selections, but that will most likely not apply to your language, so I didn't pursue exactly how to do it.)
The Code Templates menu is available through Window->Preferences.