How to wrap selected text with Markdown delimiters in Scrivener?

I use Markdown to write in both Scrivener and Obsidian. I’m not particularly interested in Obsidian’s rich‑text preview, nor in adding that capability to Scrivener. What I miss from Obsidian is its typing aid that automatically wraps a selection with Markdown delimiters—e.g.: *...* or **...** for italics or bold, ==...== for highlights, etc. With a single keystroke, the selected word or phrase is surrounded by the appropriate symbols, saving a few clicks and keystrokes each time I want to apply formatting to text I have already written.

Is there any way to achieve the same behaviour in Scrivener on Windows? I’m open to built‑in shortcuts, third‑party macro tools, or any other workaround you have discovered.

Thank you for your help!

1 Like

To share some orthogonal ideas: how I work is to find a way to have the best of both worlds, rather than a really cut-down version of one world (which I think is the best you’re ever going to get from macros, text expansion tools and such).

This way of working dodges multiple problems, most of which all stem from how Scrivener’s weakest point is its text editor. Anything starting from a “word processing” baseline is in my experience going to be pretty weak. At least I’ve never seen anything in the LibreOffice, “Google Docs”, Word, or even WordPerfect spectrum that remotely approaches the utility of a text editor like Sublime Text, VS Code or Vim—and with those you can add Markdown typing aids on top of them.[1]

And that’s what it really boils down to. Could I put Markdown typing aids on top of Scrivener’s editor? Sure… but why? It’s still a word processor style text editor that is (excluding all the fluff about rich text) realistically about as capable as the box I’m typing into, in this browser, while responding to you. Ctrl+End, Ctrl+LeftArrow, Ctrl+C, Ctrl+V… not much. Or, I want to avoid having a really cut down version of one thing (basic macros instead of a full Markdown writing suite), but if you put basic macros on top of a really basic text editor—isn’t that the worst of both worlds?[2] :laughing:

But, to answer your actual question, yes something like is probably a good start:

I bet it wouldn’t be hard to modify some of those to allow for a hybrid approach of it being more for modifying existing text. For example, selecting a word or phrase and pressing Alt+B to wrap it in asterisks is way more useful to me. If I were designing this, that is 100% more the route I would take. I’ve never quite understood memorising keyboard shortcuts to insert characters that take just as much effort to type in directly. Isn’t that a major selling point of writing with Markdown, that you can just type it all out easily?

On the other hand though, something that takes a URL from the clipboard and produces, [Previously selected text](clipboard)? Absolutely, why not. That’s demonstrably easier, as is even **previously selected text** (though, the latter is again much easier in a proper text editor rather than thrashing about in something that bumbles through text like a word processor).


  1. Curiously, I find Obsidian’s editor to be about equally deficient in these regards. I suppose for that matter a lot of custom built Markdown editors may have that same flaw, and maybe that’s why I’ve generally always preferred coding editors with Markdown plugins. ↩︎

  2. I mean no offense at all to the macro creators out there! The point is, there is only so much you can do without a full plugin SDK. ↩︎

2 Likes

I see the point, and I would move in that direction if I did not feel that what I am missing from Obsidian (so far) is only a very tiny feature. I am not sure if that setup (which, even if it is not very complicated, is still more complicated than just writing on Scrivener) is justified only to save me the effort of pressing Ctr+8 twice. My needs are simple: all the markdown I use is for bold, italics, and quote blocks, plus parentheses and brackets, which Obsidian handles the same way.

(I write in Scrivener and Obsidian, but not for the same purpose. Scrivener for things that I want to publish or print, and Obsidian as my private knowledge database. Another reason I do not need to have them synced.)

This is one reason why I have started writing with Markdown. Memorising keyboard shortcuts for different apps, across different keyboard layouts, and on various computers has been a mess and a waste of time over the years. So I completely agree: the right approach for me is to type the character I need directly. However, being able to select some text, type that character, and have it wrap the text saves me a few keystrokes and clicks each time. That is the tiny feature I miss from Obsidian.

With this in mind, I have tried macros with AutoHotkey, without much success. I discarded the approach of the script you referred to, because it would force me to learn a new set of shortcuts, while I simply want to type * or ( like I would type them in any other editor or keyboard. I have successfully had AutoHotkey make it work for *, but not for other keys. The reason is apparently that I use Alt and not Ctrl to insert asterisks on my keyboard, but for characters that require Ctrl, there is a conflict with Ctrl+c, which the macro uses to prevent the selected text from being deleted.

In sum, things have become a bit complicated this way as well, and are beyond my capacity. Even if it works well with asterisks (and that will already save me a few clicks and keystrokes), it still feels clunky, possibly confirming what you said:

I see the point, and I would move in that direction if I did not feel that what I am missing from Obsidian (so far) is only a very tiny feature.

All right, it is clearer to me what you are looking for. I wasn’t sure if you were looking for alternative shortcuts for formatting, which I think that particular script is better for, or a much broader suite of typing aides.

The notion of being able to select text and hit a punctuation mark to surround it, instead of replacing the selection—in and of itself is something I definitely do have on our list for consideration, because that’s not even something we just get requests for from Markdown writers. Every kind of writer could benefit from being able to easily make a selected phrase within a sentence a parenthetical, or to mark off quotes around text, or even to auto-complete these pairs as you type forward. Having a field somewhere in settings where you can type in punctuation you want to use as pairs makes good sense to me.

As to the larger topic of using two programs together on the same data, I was thinking more broadly of the many things Markdown plugins and software do to speed up typing and auto-complete, and comfortable it is for extended writing sessions in them. For example, I make heavy use of the listing tools in my editor, which number lines for me, make bulk nesting operations a snap. There are dozens of things I use of that nature, on top of the one you describe where selecting text and hitting certain forms of punctuation will surround the selection in that pair.

Once you do have something like this set up, it’s extremely low overhead, at least in my experience. It is little different than switching back and forth between the binder and the editor, you just punch a “sync now” shortcut now and then when switching between the two.

Again, I personally wouldn’t pair Obsidian with Scrivener in this way, for that purpose, as I don’t find Obsidian’s editor to be that much of an improvement—but it would certainly work well for that. For myself, it is not just the Markdown typing aids I miss in Scrivener, it’s the extensive raw text editing features that special-purpose text editors have a bounty of.

Hmm, well one small little trick for this that works just about anywhere, that is better than manually positioning the cursor before and after the range of text, is to select it as you would, then cut, punctuate, paste, punctuate.

3 Likes

You could write an AutoHotkey script triggered by keyboard shortcuts to surround a selected word or words with markdown symbols.

There is a thread dedicated to creating such macros. I bet the folks who have contributed scripts would enjoy noodling this with you. Please share your AutoHotKey macros for Scrivener - Scrivener / Scrivener for Windows - Literature & Latte Forums

Update: And of course, I didn’t read the full thread first. I see that @AmberV has offered deep insights into the “why” of this approach while also providing a link to a script.

2 Likes