4

If I have a shell script with code like

...
chars+=('5')
chars+=('6')
...
chars+=('%')
chars+=('&')
...

and iskeyword is defined as

iskeyword=@,48-57,_,192-255,-

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

chars+=('5')
 ^ (cursor)
chars+=('6') 

and press w

chars+=('5')
     ^ (cursor)
chars+=('6')

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.

4

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.

  • 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

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.