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

3

32

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.

Copper answered 9/12, 2010 at 14:10 Comment(1)
That camelcase navigation so insanely annoying. Some dude requested that weird behavior and they made it default... On top of that, eclipse that comes with android SDK totally doesn't handle properly Ctrl+Left/Ctrl+Right...Interfile
D
43

Try and unselect the option:

Preferences / Java / Editor / Smart caret positioning in Java names

alt text

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.

Deepseated answered 17/12, 2010 at 12:9 Comment(8)
I think I tried that before I posted the question. But I will re-check. Thanks.Copper
I wonder, what if I still need to be able to jump to next camel-fragment of the word in some other way. E.g. in Xcode I can iterate though words with alt+arrow and though camel case with ctrl+arrow. How do I do it in eclips?Wallenstein
@Danich I didn't see that feature, either in Eclipse nor in a plugin. I only saw this Camel completion study for CDT: wiki.eclipse.org/CDT/C_editor_enhancements/…. But it doesn't cover your case.Deepseated
It seems so obvious feature... What is the most efficient way to ask them about it? I think may people need this functionality.Wallenstein
@Danich Probably making a feature request on bugs.eclipse.org/bugs, and ask as many people as you can to vote on it.Deepseated
With this option disabled, Ctrl+Left/Right treats each individual tab character as a "word", which is a nightmare for users who indent with hard tabs. It also treats both the beginning and end of _ in a Java identifier as a word boundary, so you'll have to hit Ctrl+Right 3 times to skip past the identifier x_y.Gytle
Smart caret positioning at line start and end has nothing to do with this.Hellfire
@Wallenstein As a fellow XCode user, I agree. I did figure this out, and it's posted here as an answer now.Icebreaker
I
10

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.

Icebreaker answered 3/3, 2014 at 0:7 Comment(1)
by default Alt+Left/Right is for moving to the previous/next placeEnumeration
S
1

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

Schoonmaker answered 29/8, 2019 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.