How to turn of copy unselected line?

If there is no text selected, Ctrl+C will copy the active line. This is driving me crazy and its destroying my clipboard.
I would like the standard windows behaviour please: If there is no text selected, Ctrl+C should do nothing

VSCode has a similar functionality by default but provides an option to disable it:

"editor.emptySelectionClipboard": false

Is there such an option in obsidian? If not, is there an alternative keyboard shortcut command that I can map Ctrl+C to, that will do nothing IF there is no text selected.

I searched on Reddit/Google etc, nothing turned up. I created an account just for this issue, I would appreciate any help. Thanks.

1 Like

I’ve found a workaround related to QuickAdd macros, and execution, which seemingly seems to do what you want it to do. It does however require a little bit of setup.

Create a file, e.g. newCopy.js, somewhere within your vault, with the following contents:

async function newCopy(params) {
  const selection = await app.workspace.activeEditor.getSelection()

  if ( selection)
    navigator.clipboard.writeText(selection)
}

module.exports = newCopy

Go to Settings > QuickAdd, and change the line somewhere near the middle to match this, before you then hit the Add Choice button:

You’ll now get a new line (with your new choice) at the end of the list above the line with the button. First of all hit the lightning symbol on right side, and then hit the cog wheel right next to it. You’ll now get this dialog window:
image

It’ll show something unrelated, so hit the + button, and it’ll change to “newCopy”, and you can then hit the cog wheel to the left of the + button. Which opens the following dialog window:

image

Click in the User script box, and you’ll get a drop down where you should be able to locate the newCopy.js script from above. Note that the folder it’s placed in is irrelevant, as long as it is somewhere within your vault. (You can also start typing “newCopy” to find this script). When found/selected, hit the Add button to the right of this script, and close the dialog window, and the previous dialog window.

Now go to Settings > Hotkeys and add “QuickAdd” to the filter dialog, and you should see your new command in there. On the righthand side it should say: blank +, and you can hit the + to assign your hotkey to it.


After doing all of these setup, you should now have a copy command which only replaces the clipboard if you’ve made a selection in the current editor. I’m not sure whether this will affect copying on non-editor windows, or how it’ll affect those.

If that proves to be a problem, change the hotkey to something like Shift Ctrl C to be your new improved copy command, and allow the default copy command to do its thing in those cases.

1 Like

Wow so kind. I will get started on this, I dont care if it takes me the whole day to get it set up. Thank you so much for taking the time to do this. really appreciate it!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.