Search code examples
linuxvimediting

Change delimiters for navigating word-wise


When programming/writing I heavily use word-wise commands, for example "move to the left/right by one word", "delete next/last word" by pressing Ctrl (+left,backspace...).

The problem I have is, when the text I am editing contains symbols which will not be recognized as words, therefore ctrl + right will jump over a sequence of symbols AND a regular word after that.

Ideally I want to be able to set the delimiting characters for word-wise operations to space, tab, newline and opening and closing brackets - maybe also arithmetic operators (similar to how Eclipse handles it).

I am using Linux. Do you know any way how to change my settings system-wide or alternatively for xterm and (g)vim individually to achieve this?


Solution

  • Most likely, system-wide won't work. VIM is easy, you can set the characters that define the identifier using the iskeyword setting. In your case, there is too much in it, and you need to remove the ones you do need, or redefine it by adding the ones you do want. eg:

    :set isk=9,32,50-51
    This will set keyword detection to spaces, tabs and parentheses.

    However, in VIM you can jump based on word and WORDs, where the first is defined by the abovementioned iskeyword setting, while the latter will jump over all non-blank characters. Maybe, that's the motion you want. You can read more about this in the help (:help w).