what does iskeyword option do?

58 views
Skip to first unread message

FlashBurn

unread,
Feb 25, 2015, 11:02:46 AM2/25/15
to vim...@googlegroups.com
I'm trying to understand the meaning of 'iskeyword' option but I can't figure out from the help what it does. Any help in finding out of the meaning of this option is greatly appreciated.

Ben Fritz

unread,
Feb 25, 2015, 11:30:52 AM2/25/15
to vim...@googlegroups.com
On Wednesday, February 25, 2015 at 10:02:46 AM UTC-6, FlashBurn wrote:
> I'm trying to understand the meaning of 'iskeyword' option but I can't figure out from the help what it does. Any help in finding out of the meaning of this option is greatly appreciated.

What's not clear? The help says: 'Keywords are used in searching and recognizing with many commands: "w", "*", "[i", etc. It is also used for "\k" in a |pattern|.'

So, it affects where the 'w' command (move to next word) stops. It affects what text the '*' command searches for. It affects what text the '[i' command searches for. It affects what other similar commands search for.

It also affects what text the '\k' character class matches when you are searching.

Search the help with ':helpgrep iskeyword' for other things it affects, for example, the CTRL-W command in insert and command-line mode, for deleting a word.

Tim Chase

unread,
Feb 25, 2015, 11:31:36 AM2/25/15
to vim...@googlegroups.com
'isk' contains a list of characters (or character-ranges) for those
characters that should be considered a "word". This comes into play
when using "\<", "\>", "\k" and "\K" in a regular expression; what
gets considered when you use "*" and "#" to search; what the "iw" and
"aw" text-objects select; what's considered a "w"ord motion; how
abbreviations are found; and plenty of other places.

For example, by default "-" isn't part of the 'isk' setting, but if
you wanted "vip" to highlight/select whole CSS selectors like
"background-color"

:set isk+=-

to add the dash. Now, if you do "viw" anywhere in the attribute,
it will highlight/select the entire "background-color" not just
"background" or "color".

It's a little tricky to add certain characters as they have special
meaning. The easiest way I've found is to make a range of length one
for "@":

:set isk+=@-@ " add an at-sign, good for email addresses
" and Python decorators

-tim




FlashBurn

unread,
Feb 25, 2015, 1:49:52 PM2/25/15
to vim...@googlegroups.com
I was trying to understand if it has a meaning in the highlight context. I'm going through an online book, Learn Vimscript the Hard Way and in the following chapter, http://learnvimscriptthehardway.stevelosh.com/chapters/46.html, it talks about the # symbol not being in iskeyword in the context of comments and highlighting and I can't figure out why this matters. I think I'm getting the meaning of this option, i.e. it defines what a word is, but why it matters in highlighting, that is not clear to me.

Charles Campbell

unread,
Feb 25, 2015, 2:03:40 PM2/25/15
to vim...@googlegroups.com
Syntax highlighting is based upon regular expressions (see :he regexp).
A commonly used thing to pick up on are: words. Most variables,
function names, and commands, for example, fit into the description of
"word". Hence, the scripts that specify syntax highlighting often use
the \k atom (see :help /character-classes); and the \k atom depends upon
the iskeyword setting. For example, syntax/latex.vim (by default)
removes the underscore from the iskeyword option because latex will
(usually) flag usage of it as an error.

Regards,
Chip Campbell

FlashBurn

unread,
Feb 25, 2015, 4:21:32 PM2/25/15
to vim...@googlegroups.com
Thanks a lot Chip. That cleared it up.

Erik Christiansen

unread,
Feb 26, 2015, 5:57:34 AM2/26/15
to vim...@googlegroups.com
On 25.02.15 10:32, Tim Chase wrote:
> On 2015-02-25 08:02, FlashBurn wrote:
> > I'm trying to understand the meaning of 'iskeyword' option but I
> > can't figure out from the help what it does. Any help in finding
> > out of the meaning of this option is greatly appreciated.
>
> 'isk' contains a list of characters (or character-ranges) for those
> characters that should be considered a "word". This comes into play
> when using "\<", "\>", "\k" and "\K" in a regular expression; what
> gets considered when you use "*" and "#" to search; what the "iw" and
> "aw" text-objects select; what's considered a "w"ord motion; how
> abbreviations are found; and plenty of other places.
>
> For example, by default "-" isn't part of the 'isk' setting, but if
> you wanted "vip" to highlight/select whole CSS selectors like
> "background-color"
>
> :set isk+=-
>
> to add the dash. Now, if you do "viw" anywhere in the attribute,
> it will highlight/select the entire "background-color" not just
> "background" or "color".

That all seems to confirm that "iskeyword" is a misnomer for what in
reality is "istoken", AFAICT. Not only is token boundary recognition the
process described above, but the process in no way resembles detection
of a member of a keyword set, like those use in 'C': "if", "switch",
"case", etc.

If it were "isword", rather than "iskeyword", then the name would also
be truthful, and more easily understood, I guess.

Erik

--
Australia ranks 44th for average connection speed, according to The State of the
Internet Report from cloud service provider Akamai.
- http://www.abc.net.au/news/2015-02-09/remote-rural-australians-to-wait-another-year-for-fast-internet/6079476

Ben Fritz

unread,
Feb 26, 2015, 11:39:59 AM2/26/15
to vim...@googlegroups.com, dva...@internode.on.net
On Thursday, February 26, 2015 at 4:57:34 AM UTC-6, Erik Christiansen wrote:
> That all seems to confirm that "iskeyword" is a misnomer for what in
> reality is "istoken", AFAICT. Not only is token boundary recognition the
> process described above, but the process in no way resembles detection
> of a member of a keyword set, like those use in 'C': "if", "switch",
> "case", etc.
>

Actually it has a great deal to do with keyword detection. One use of 'iskeyword' is in syntax definition files, when using "keyword" type matches. :help :syn-keyword.

Syntax highlighting in Vim predates my use of Vim by many years. But since keyword highlighting is the most basic sort, I'd guess it was the first introduced.
Reply all
Reply to author
Forward
0 new messages