Can you disable the cut line function of cut shortcut (Ctrl+X) in VSCode?

Viewed 437

If you have a selection, cut (Ctrl+X) will copy and delete the selection. If not, it will copy the whole line and delete it.

I want to disable the latter. It is close to save (Ctrl+S) and I don't want to delete my whole line when I want to save.

Can you disable the cut line function of cut shortcut (Ctrl+X) in VSCode?

What I have tried:

  • Add when clause to cut: editorHasSelection:

    Keyboard Shortcuts menu looks like this: Keyboard Shortcuts menu

    My keybindings.json:

    [
        {
            "key": "ctrl+x",
            "command": "editor.action.clipboardCutAction",
            "when": "editorHasSelection"
        },
        {
            "key": "ctrl+x",
            "command": "-editor.action.clipboardCutAction"
        }
    ]
    

    After saving and reopening VSCode, cut still works the same.

  • Remove the second shortcut from keybindings.json:

    My keybindings.json:

    [
        {
            "key": "ctrl+x",
            "command": "editor.action.clipboardCutAction",
            "when": "editorHasSelection"
        }
    ]
    

    Keyboard Shortcuts menu changes to: Keyboard Shortcuts menu

    After saving and reopening VSCode, cut still works the same.

Info

  • Ubuntu 20.04
  • Visual Studio Code version 1.55.2
  • Recreated on Code - Insiders 1.56.0-insider (13f1aff, 2021-04-28T04:52:56.570Z)
2 Answers

This was a bug which is now fixed and released as of 1.56.0 (Issue).

alexdima from VSCode team's response is:

ctrl+x is just special and needs to be bound to a no-op to stop the default. I have added a noop command that does nothing.


    {
        "key": "ctrl+x",
        "command": "noop"
    },
    {
        "key": "ctrl+x",
        "command": "editor.action.clipboardCutAction",
        "when": "editorHasSelection"
    }

The first key binding that matches is used.

Define the Remove keybinding first

[
    {
        "key": "ctrl+x",
        "command": "-editor.action.clipboardCutAction"
    },
    {
        "key": "ctrl+x",
        "command": "editor.action.clipboardCutAction",
        "when": "editorHasSelection"
    }
]
Related