1

I'm very new to vi, so sorry if this is a dumb question. I've recently learned about the list of keyword characters, and I've noticed that vi treats strings of characters not in that list as words also. Consider the following text:

Vim---is---a great editor

To any sensible human, this text contains five words. According to vi, there are seven. If I move with Shift+W instead of w, there are three.

If I have the above text in my buffer and I type 2w, it will move the cursor to the beginning of is. I find this behavior confusing and not especially useful, and I would like to find a way (either through a different key to press, a macro of some sort, or an editor setting) to treat the non-keyword characters as whitespace, so that the same motion would move the cursor to a instead. Is such an act possible, either in vim or in neovim?

1
  • 1
    Someone more knowledgeable might give an answer, but I'll point out that the f, F, t, and T normal mode commands are useful in jumping the cursor to particular characters (and the , and ; commands jump to the next/previous instance).
    – mattb
    Mar 30, 2022 at 7:22

1 Answer 1

1
                            *word*
A word consists of a sequence of letters, digits and underscores, or a
sequence of other non-blank characters, separated with white space (spaces,
tabs, <EOL>).  This can be changed with the 'iskeyword' option.  An empty line
is also considered to be a word.

This explains why --- is considered a "word"—it's a "sequence of other non-blank characters."

Unfortunately, adding - to iskeyword means the whole first WORD is also a word, so that won't do it.

You could, however, bind w to /\<Enter. This works, but I caution against it: to make this work seamlessly, you need to bind normal-mode, visual-mode, and operator-pending-mode w correctly. And if you ever use vim without this customization it won't do what you expect, which is occasionally frustrating.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.