If I have a shell script with code like


and iskeyword is defined as


This definition indicates to me Vim will consider a continuous sequence of characters from these iskeywords characters to be a word.
So if I am here

 ^ (cursor)

and press w

     ^ (cursor)

I end up on + which is not the beginning of a word as defined by iskeyword character set. Why? Does Vim stop at the beginning of a group of these non-iskeyword chars because it considers you might be interested in doing something with them?

In this case, wouldn't it be better to say w takes you both to the beginning of the next "word" OR the beginning of the next "anti-word" (continuous sequence of characters NOT defined in iskeyword)?

Because code contains a lot of characters not in iskeyword, I am interested in knowing the rules for "w" word motion regarding these non-word characters.


I think the misunderstanding is that iskeyword doesn't define what a word is; rather, it adjusts where a boundary may happen by adjusting what a keyword is. Both keywords and non-keywords are still "words".

According to :help 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, ). This can be changed with the 'iskeyword' option. An empty line is also considered to be a word.

But, that doesn't quite answer your question exactly.

My understanding is that "iskeyword" is used to group the containing characters as a type of word called "keyword", but that doesn't mean that characters (except whitespace) outside of iskeyword aren't words, but are just non-keywords. Also, it seems that letters and high unicode is considered part of a keyword regardless (from help 'iskeyword' and help 'isfname').

As such, when you press w at the beginning of chars+=, the letters are considered part of the same word because they form a keyword, but since + and = are not in iskeyword, that makes them a non-keyword word, which means there is a word separation.

The behavior that I observe is that, outside of whitespace separation, keywords and non-keywords are considered words, and a transition from keyword to non-keyword or from non-keyword to keyword forms a word boundary, just like whitespace forms a word or WORD boundary.

| improve this answer | |
  • interesting, I assumed vim uses the term "keyword" in the variable "iskeyword" (rather than "isword" ) because the iskeyword group serves more purposes than just motions, e.g. completions etc. – the_velour_fog Apr 2 '16 at 3:57
  • Thank you for clarifying this. Most explanations of the defintion of word/Word seem to imply that distinct words must be separated by something between them, be it a whitespace or some special non-word character. But in practice, distinct words can be adjacent to one another without any whitespace or non-words between them. So really the definiton of word shold be A word consists of a sequence of (letters OR digits OR underscores i.e. keywords), XOR (a sequence of other non-blank characters i.e. non-keywords), separated with white space (spaces, tabs, ) – Nicholas Cousar Aug 30 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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