The default behaviour of Ctrl+X
in VSCode in the absence of selected text is to cut the current line. I would like to configure VSCode so that Ctrl+X
only works if text is selected. I have tried adding the following to my keybindings.json
file
[
// Cut only when selection
{
"key": "ctrl+x",
"command": "-editor.action.clipboardCutAction"
},
{
"key": "ctrl+x",
"command": "editor.action.clipboardCutAction",
"when": "editorHasSelection",
},
]
but it does not seem to take effect. What is the correct way to make Ctrl+X
work only if text is selected?
2
Answers
Thanks to @rioV8's suggestion to keyboard troubleshootting functionality, I realized that even though
Ctrl+X
was not bound to any command, the default action by VSCode was to still cut the current line.I have fixed this by binding
Ctrl+X
to something that does nothing when no text is selected.You can use the relatively unknown command
noop
(no operation) here to make this a little better: