0

I want some abbreviations for common things typed in e-mails want to start them with a semicolon.

iabbrev ;ph 555123467

But this gives me an error:

E474: Invalid argument

I can have semicolon later in the abbreviation, but not as the first character. Is there a way to escape the semicolon or otherwise allow it as the first character in my abbreviation?

1
  • Another solution is to have a mapping on h that detects its context. Alas, this approach is excessively intrusive and all abbreviations will then need to follow this schema -- see IMAP.vim with is (also) shipped with vim-latex. I remember this question has duplicates, possibly on SO. – Luc Hermitte Dec 3 '18 at 14:58
2

From :h abbreviations we can read:

There are three types of abbreviations:

full-id     The "full-id" type consists entirely of keyword characters (letters
            and characters from 'iskeyword' option).  This is the most common
            abbreviation.

            Examples: "foo", "g3", "-1"

end-id      The "end-id" type ends in a keyword character, but all the other
            characters are not keyword characters.

            Examples: "#i", "..f", "$/7"

non-id      The "non-id" type ends in a non-keyword character, the other
            characters may be of any type, excluding space and tab.  {this type
            is not supported by Vi}

            Examples: "def#", "4/7$"

So it seems that the only solution is to add ; to iskeyword with set iskeyword+=;, note that it might not be the best solution since it will change the behavior of a lot of other things (see :h 'iskeyword')

So personally I would recommend not to use abbreviations beginning with ; or setting ; as a part of iskeyword but only on filetype-specific configurations.

Another solution is to create a "non-id" abbrev and simply add another ; at the end of the left hand part like this:

iabbrev ;ph; 555123467
3
  • I see. End-id type requires ALL but the last be non-keywords. So ;;p would work, but not ;ph. Unfortunately I have 1 leading semicolon in muscle memory from elsewhere and its a good way to avoid conflicts with things I might actually type otherwise. I'll see if changing iskeyword is acceptable in my limited context. – Rob Mosher Dec 3 '18 at 18:42
  • @RobMosher Indeed you might have to change your habits. If you end up using another solution don't hesitate to post it as an answer here so that it can help future readers. Also don't forget to accept the answer which will have solved your problem. – statox Dec 4 '18 at 13:02
  • In the end I set this up in QMK on my keyboard, ultimately a better solution. Now, I have my abbreviations everywhere as long as I have my keyboard, which is what I really wanted. I was only implementing in vim as AutoKey in Linux didn't handle vim well. – Rob Mosher Apr 19 '19 at 19:14

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.