Automatically replace two hyphens with an em-dash

Hello Obsidian team, thank you for creating this amazing product. I really like using Obsidian- its UI/UX makes it an absolute delight to use as my main KMS, and it’s starting to change my life.

I have one low-hanging feature request that’d immediately alleviate a lot of pain: Please automatically replace two hyphens in a row (–) with an em-dash (—)! This behaviour is observable in Notion for example. This has been mentioned before in a broader thread.

13 Likes

This is pretty easy to replicate in Microsoft word, by setting up an auto-replace list. (Also found in apps like Zettlr.) A similar expansion of the spell check plugin would be nice.
And yes, em dashes are great.

Surely en-dashes shouldn’t be left out either

1 Like

In theory, no. The problem is distinguishing between the two. You could tell Microsoft to replace “–” with “–”. The problem is that it does this without waiting for a space. Thus, if you wanted “—” to become “—”, you would instead end up with –-. This is the problem that Zettlr has too. I think a general auto-replace plugin would let the user decide the best outcome.
I’d argue that em-dashes are more important, but en dashes are essential for citations and scholarly work, so…

2 Likes

Love this idea.
Could it be achieved by custom css? Looking for faster solution… (I have no experience with css)

One possible solution: espanso treats a backspace input immediately succeeding the two hyphens as an “undo replace” button. So we could do that, then replace upon inputting the third hyphen, right?

Alternatively, replace two hyphens with an en-dash, and upon inputting the third dash, replace the whole thing with an em-dash (which is the longest of them all)? Backspace reverts all replacements, leaving you with ---

3 Likes

I’m currently using espanso as suggested by @death.au as a workaround. It’s smooth, but it’d be best if we could have it integrated into Obsidian.

Nice, thanks!

I never really found espanso to be anywhere near as fluid as Typora’s integration, which works even if you click away and return to expand the hyphen.

On macOS, in most of the text editor apps, the system settings work for the quick text replacements while typing, so I guess one could integrate the system text replacements to the macOS Obsidian.

I also ended up using espanso, but would definitely appreciate this feature.

Also, would be great if it would turn off inside the codeblocks.

1 Like

Easy to type?

en: OPT HYPHEN

em: OPT SHIFT HYPHEN

Angel

I’d support this if it can be made optionable and modifiable. I use double en-dashes all over the place and don’t want to suddenly need to fiddle around them. However, THREE en-dashes --- are almost never used for anything, and can be straightforwardly used to convert into an em-dash.

Just like in LibreOffice/Word, you can set up auto-replace ‘scripts’ that replace certain strings with others. I’d rather see this feature implemented, and then we can program whichever replacement we want to see in our editors.


3 dashes are used to form a horizontal separation line in Obsidian. In this forum as well. I use 3 all the time. I don’t want them to ever auto-format.


3 Likes

Exactly my point. Obviously this should be user-settable :smiley:

There’s a plugin that handles em-dashes, smart quotes, and other typography.

However, it doesn’t work the way OP suggested, replacing two dashes with an em dash. That’s the way most word processing and text editors work, too. Instead, the plugin replaces two dashes with an en-dash, and then it replaces and en-dash and dash with an em-dash, and then it replaces an em-dash and dash with three dashes in a row.

I can see the sense to that, but it remains to be seen whether my fingers can learn the difference.

Personally, I am not an academic. I never use the en dash and use the em dash often. But that’s just me.

1 Like

Here from the future trying to figure out how to make three dashes for a separator because any time I make two it auto-converts
—- <— why??

Hi welcome from the future. You need to give more information. What is your OS? Each OS will have its own feature for auto-correcting phrases.

Yeah I’m assuming it is because of my device not Obsidian itself. I just found it funny that someone was asking for the exact feature I was trying to get rid of, for the exact reason you mentioned months ago! I’ve only tested it on my ipad, but since I mostly only needed it for assigning aliases in the front matter I just did it once and made it a template

In case any other newbies come upon this page via google, I was able to do - - - (dash space dash space dash) and then go and manually backspace the spaces. Intolerable to do every time, but fine to do twice in order to make a template

FWIW, the built in text replacer didn’t work either. I asked for —- to be replaced with — but it just gave me a single em dash shrug

ETA: Sorry now realizing that I replied to your comment in my first one which was probably not necessary since I wasn’t actually asking for help!