[conspire] Automatically doing em dashes in Vim?
Michael Paoli
michael.paoli at berkeley.edu
Tue Oct 7 22:03:49 PDT 2025
Not sure about vim, but vi, which it's mostly quite compatible with,
might want to use its abbrev command (which can be shortened to shortest
unique abbreviation thereof, e.g. generally ab). However, abbrev isn't
smart about context, you type the abbreviation you configured, it puts
in the replacement text you specified. Anyway, ASCII doesn't have em
dash, but it has dash / en dash / hyphen / minus - all the same as far
as ASCII is concerned (but not the same for typography). Common
convention in ASCII is to use -- where an em dash would otherwise be
used (and some programs may even render that as an em dash, where that
can be done).
So, rather than a conditional ; by context, perhaps instead do a one or
two character abbreviation that would then substitute the desired. The
abbreviation must end in a word character, so, maybe ;e, e.g.:
:ab ;e &mdash
So, then in insert/append/etc. mode, typing ;e not followed by a word
character, the abbreviation will be expanded.
If you want substitution based on context, can do that after-the-fact
with s command to substitute. E.g.:
:%s/\([A-Za-z]\);\([A-Za-z]\)/\1\&mdash\2/g
And run that twice to cover all cases,
notably if one has, e.g.:
a;b;c and the REs would otherwise overlap on the b (can't have that).
On Tue, Oct 7, 2025 at 7:59 PM Don Marti <dmarti at zgp.org> wrote:
>
> Here's a Vim question. Basically I want the semicolon key to act like an
> em dash key where it makes sense—when I'm editing a file that's mostly
> text and putting the punctuation mark between two word characters.
> (Semicolons are generally for code, not for prose.)
>
> If I'm editing an HTML or Markdown/CommonMark file, and I type a word
> character followed by a semicolon followed by another word character,
> what I want instead of the semicolon is an em dash (either the HTML
> — or the Unicode — I'm not picky.) Semicolons at the end of a
> line or followed by a space should be left unchanged.
>
> Is this doable? Pretty sure it should be but can't find anything
> directly relevant.
More information about the conspire
mailing list