Search code examples
android-studiointellij-ideaintellij-14

change word boundary intellij


Is there any way to change the word boundary in IntelliJ so that when I use the "move caret to next word" command, punctuation is ignored? (ie brackets periods quotations etc. etc.) Every time I look this up all I seem to find is tutorials on how to write Regex. Which I can see why that would be useful here, but where do I actually change the regex that defines word boundary?

Example, step by step:

current functionality:

  1. |foo.bar
  2. foo|.bar
  3. foo.|bar
  4. foo.bar|

desired functionality:

  1. |foo.bar
  2. foo.|bar
  3. foo.bar|

Solution

  • To the best of my knowledge, there is no setting to modify this behavior. A search of the IntelliJ IDEA source code,as detailed below, seems to confirm this. To get the behavior you desire, you'll need to either open a feature request, or write a plug-in to do it.

    From the Source Code:

    The "Move Caret to the next word" action is done via the NextWordAction class.That action uses the NextPrevWordHandler to do the work. NextPrevWordHandler only has three boolean options:

    1. next
    2. withSelection
    3. inDifferentHumpMode

    These booleans are set in different permutations for the various actions that use this handler:

    • NextWordAction
    • NextWordInDifferentHumpsModeAction
    • NextWordInDifferentHumpsModeWithSelectionAction
    • NextWordWithSelectionAction
    • PreviousWordAction
    • PreviousWordInDifferentHumpsModeAction
    • PreviousWordInDifferentHumpsModeWithSelectionAction
    • PreviousWordWithSelectionAction

    The NextPrevWordHandler in turn calls EditorActionUtil.moveCaretToNextWord(...). Likewise, it does not take, or reference, any sort of word boundary setting. Thus there does not appear to be a way to modify the behavior to do what you desire.