Simple way to copy inline code

The new version of Obsidian allows to copy code in fenced code blocks to the clipboard, which is very useful. Sometimes, I also want to copy inline code (not blocks). It would be nice if that would be possible in a similarly easy way. Currently, it is cumbersome, you have to select the text carefully with the mouse, or when you click on “Copy” in the context menu, you need to remove the backticks. A simple solution would be to add a “Copy plain” menu entry to the context menu that only copies the inner code without the backticks. Or maybe make that the normal behavior if you click “Copy”.

19 Likes

I need this feature too.

I usually backup some command line code as inline code, it would be convenient if the copy of inline code can be done by simpler operation.

2 Likes

+1. Logseq has this.

Duplicate request in the bug graveyard

Are we holding it wrong?

I think it doesn’t make sense to include the backticks:
It makes it completetly unusable for comfortable code copying.
In case it’s a shell command the effect is that the command is executed and it’s output then tried to be executed as a command, too! That’s rarely what you want.
And as part of source code it’s also very hindering.

But it has been implemented to include backticks by default.

I wonder why this was chosen?
What is the usecase for the backticks?
How does it compare to the one of code copying?

1 Like

Registered to support this future request. Very needed indeed.

1 Like

+1 I would also like this function.
It would be great if the inline code could be copied automatically when you click over it at least in Reading mode, like in Telegram.

1 Like

+1 to this feature.
Single-click copy, like Telegram has with monospace formatting, would be awesome for storing little code snippets.

1 Like

Logseq doesn’t have this. When selecting code formatted within backticks, it enters edit mode and starts the selection exactly under the cursor. Assuming a right-to-left movement, this is often just before the closing backtick, as it appears to the right of the cursor.

LS2

While this is better than Obsidian, it is still not good because you still have to carefully drag the cursor instead of just double-clicking.

One way to implement this would be a “Copy without Formatting” akin to “Paste without Formatting” (funnily named “Paste and Match Style”):

Use Ctrl + Shift + C to copy the selection without enclosing backticks.

This keeps Copying via Ctrl + C as is – copies exactly what is selected – and gives clear implementation criteria for when to strip backticks.

I also think this issue should be solved not for Editor mode, but for Preview mode. I would like to compare with Telegram, which also supports a subset of Markdown. In Telegram, when you send message with inline code, it becomes copy-able by a single click/tap on the block. I think this behavior would fit Obsidian too. And if you want to copy with backticks (and other formatting) – select text with mouse and hit Ctrl + C – exactly as it is right now.

It has been a while but I want to notify you that a simple plugin has been developed. It has some limitations but it works for now.

Excellent solution, @JamesLemony This plugin finally makes inline code useful to me.

1 Like