Disable Ctrl-X / Cmd-X cut unselected paragraph

An older tool is Clipangel I like there. You can favorite text and clipboard images with it and has various other functions.

On Linux, I make do with CopyQ.

On both platforms, these must be added to StartUp apps.

Yurceeā€™s solution is really helpful and solves the issue for me. It is so much better than disabling cut entirely which was my initial response and later suggested by Hampton.

For other people wanting to solve this issue I wanted to summarise the three solutions suggested by others in the community and highlight the one by Yurcee because I think it might achieve what people are wanting if they have similar needs as me.

  1. Custom keyboard shortcut on macOS to disable cut - suggested by Hampton in thread but also was my go to solution at first but removes cut functionality from Obsidian
  1. Clipboard history tool suggested by rigmarole
  1. My preferred solution is the one suggested by Yurcee which is a snippet - I keep the notifications off because then it makes cut act more predictably

The third solution is really direct and solves the issue. Other solutions are good to keep in mind or even use for other things but if you want cut to act like it does in other programs the third solution is ideal. Thank you Yurcee.

Happy note taking everyone :smile:

1 Like

Note: I had to tweak the template to make sure text is written to clipboard but no notification is displayed. This just meant commenting out only part of a line in the above solution.

<%*
// Get the active editor and selection
const editor = app.workspace.activeLeaf.view.editor;
const selection = editor.getSelection();

// If no text is selected, do nothing
if (!selection) return;

// If text is selected, cut it and notify the user
editor.replaceSelection(""); // Cut the selected text
navigator.clipboard.writeText(selection); //.then(() => {
//    new Notice(`Text cut to clipboard:\n${selection}`, 3000); // Notify for 3000ms
//}).catch(err => {
//    console.error('Could not copy text: ', err);
//});
_%>
1 Like

Uh, sorry about that. Iā€™ve overbitten it. Iā€™m so used to having Obsidian take care of the cut operation and having stuff automatically on the clipboard.

I edited my own post too.

1 Like

Thereā€™s another caveat though:
If you have no active md note open, e.g. you are in the url bar of the Surfing plugin, you cannot cut there, only copy.

This is great, but I still think weā€™re working around something that shouldnā€™t be default behavior. Cmd-X is ā€œcut selected textā€ on both Mac and Windows and has been since literally the start of both OSes. Leave it that way and let people turn on other behaviors, if they want.

Iā€™m just repeating myself now, so Iā€™ll stop. :slight_smile:

1 Like

This can be tackled by opting for a non-Templater solution in the form of a command of a pseudo-plugin, using the so-called User Plugins plugin.
Create a .js file (e.g. ā€˜Override built-in CTRL+X behavior.jsā€™) with this content:

module.exports = {}
module.exports.onload = function(plugin) {
    plugin.addCommand({
		id: 'cut-override',
        name: 'Cut override',
        callback: () => {
            const editor = app.workspace.activeLeaf.view.editor;
            const selection = editor.getSelection();

            // If no text is selected, do nothing
            if (!selection) return;

            // If text is selected, cut it and notify the user
            editor.replaceSelection(""); // Cut the selected text
            navigator.clipboard.writeText(selection).then(() => {
                new Notice(`Text cut to clipboard:\n${selection}`, 3000); // Notify for 3000ms
            }).catch(err => {
                console.error('Could not copy text: ', err);
            });
        }
    });
}

Add in the settings of User Plugins the folder where you keep your script files (.js), and then you can toggle this script on.
From this point on, you have a ā€˜Cut overrideā€™ command registered through the User Plugins helper and can bind CTRL/CMD + X to this command.
The plus of this method is that you will be no longer reduced to being able to use the script in the main editor area but anywhere at all without errors.

One of the easiest ways for this to happen if the user means to undo a behavior (typically ctrl/cmd-z) and doesnā€™t notice immediately that text has been deleted instead. On cheap keyboards, thatā€™s an easy mistake to have happen consistently, especially when both keys are typically hidden from view by oneā€™s left hand.

Cutting/copying the entire line is a feature commonly found in programming editors, like Visual Studio Code or JetBrainsā€™ various IDEA-based IDEs. The feature can be very useful there because when programmers start moving code around, itā€™s often a line-based process (i.e., you donā€™t want just part of line). However, even in such environments, users can almost always turn off line-based clipboard operations because many find it an annoying feature.

In an app thatā€™s more often used for long-form text, however, Iā€™m not sure the feature makes sense. Itā€™s absolutely a non-standard tweak to a behavior that most users rely on without any thought. Then again, given Obsidian gets used with so many types of content, Iā€™m sure many folks actually are working with line-based content (such as various lists) and do/would find it useful. Myself, I didnā€™t realize the feature was there until I stumbled on it testing an automation macro I was building to create internal links with display text, and I realized my macro breaks in a particular scenario because of this feature. That said, Iā€™d definitely find it helpful with some of the content I work with.

All of which is to say that I strongly agree that Obsidian should adhere to the standard cut/copy behaviors. Itā€™s just not the type of software where most users wonā€™t be surprised by line-based behaviors. Butā€¦ I also think the line-based versions should remain available. Ideally, I think it should be available as a separate command so that itā€™s always available and its keystroke can be customized (perhaps the default should be something like cmd-opt-X/C).

1 Like