开发者

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 w开发者_StackOverflow中文版ord 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?


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).


Instead of holding down the control key and pressing the left/right cursor keys, why not use Vim's normal mode word motion commands?

  • w/W - move to start of next word/WORD
  • e/E - move to end of next word/WORD
  • b/B - move to beginning of previous word/WORD
  • ge/gE - move to end of previous word/WORD

You can read up on the difference between a word and a WORD by running :help word.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜