Karl Brandenberger
Karl Brandenberger

Reputation: 23

How do I escape characters in a vim abbreviation?

I'm trying to make this abbreviation in my Vimrc for markdown editing:
iabbrev ,,img ![<alt-text>](<img-link>)

I think the parenthesis need to be escaped here, but I'm not sure how to escape these characters without including the escape character in the abbreviation as well.
What should I do?

Upvotes: 1

Views: 692

Answers (2)

Peter Rincker
Peter Rincker

Reputation: 45087

Abbreviations come in the following forms (See :h abbreviations):

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$"

,,img can not be a full-id as it starts with ,. It can not be end-id as all other characters have to be non-keyword characters. It can not be non-id either.

I would recommend changing your abbreviations. e.g. img,,

Upvotes: 4

joanis
joanis

Reputation: 12193

In my attempts to reproduce your problem, I find that vim gives me an error due to the two commas in the left-hand side of your abbreviation, ,,img.

These work for me:

iabbrev img ![<alt-text>](<img-link>)
iabbrev __img ![<alt-text>](<img-link>)

while this:

iabbrev ,,img ![<alt-text>](<img-link>)

gives me error:

E474: Invalid argument

Upvotes: 1

Related Questions