3

I wonder how one can add characters such as (yes, space!), ' (single quote), " (double quote), etc., to iskeyword.

This is not a theoretical exercise. The purpose is iabbrev for these. I noticed that if you add a character to iskeyword, then use it for iabbrev, and then remove it from iskeyword, the abbreviation still works.

Adding space, would make it possible to e.g., to define two word abbreviations.


EDIT I double checked. This works. Take the following as an example:

set iskeyword+=^
set iskeyword
iabbrev ^0 ⁰
set iskeyword-=^
set iskeyword
3
  • 2
    Are you sure about this: if you add a character to iskeyword, then use it for isabbrev, and then remove it from iskeyword, the abbreviation still works.? From my experience this does not work. Once you change your 'isk' setting you may disable abbreviations. Note also, since the 'isk' setting is used for may things, it is usually a bad idea to mess with it. It breaks in too many different places. Jan 7 '16 at 7:42
  • I double checked. It works! Editing the question.
    – Yossi Gil
    Jan 8 '16 at 9:36
  • For me, iabbrev 'a foo and iabbrev "a foo work without having to mess with iskeyword.
    – muru
    Jan 8 '16 at 10:38
3

Your example already works, without messing with the 'iskeyword' setting.

That is, because your example is an abbreviation of type end-id as can be read at :h abbreviations.

Here is an example, that would only work, if you change your 'iskeyword' setting:

:set isk+=,
:iabbrev abc,def ABCDEF

Now enter insert mode and type "abc,def" and see how this is changed to ABCDEF. Now reset your iskeyword setting: :set isk&vim and enter again "abc,def" and note that the abbreviation does not work and if you enter the :iabbrev command again, you will see an error E474 invalid argument.

BTW: In general it is not recommended to change the 'iskeyword' setting, because it messes with too many different things (motions, syntax highlighting, regular expressions).

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.