31
votes

Visual Studio has by default the shortcut Ctrl+l (cut line). It copies the line where the cursor is to the clipboard and deletes it.

I cannot find it in Visual Studio Code. Is there a way to add it as end user?

(I know there is Ctrl+Shift+K for delete line, which is not the same)

3
CMD/Ctrl+X without selection going on - Muhammad Umer

3 Answers

45
votes

What you are looking for is the editor.action.clipboardCutAction command. It cuts (copies to the clipboard then deletes the line) either a selection or the entire line if nothing is selected.
I tested it with vscode 1.23.1
On windows this command is bound to Ctrl + X as well as to Shift + Delete

3
votes

Shift + Delete on VS Code cuts the line i.e. copies the line to the clipboard and deletes it.

I am running VS Code on Ubuntu 18.

Edit: Ctrl + X also works the same way.

2
votes

I was a able to get the same functionality (i.e., mimicking Sublime Text's 'cut selection' functionality) by doing the following:

  1. Added the 'macros' extension by geddski:

enter image description here

  1. Added the following entries to my settings.json file (ctrl+shift+p, "Preferences: Open Settings (JSON)")
  "macros": {
    "cutLines": [
        "expandLineSelection",
        "editor.action.clipboardCutAction"
    ]
  }
  1. Added the following to my settings json file (ctrl+shift+p, "Preferences: Open Keyboard Shortcuts"):
  {
    "key": "ctrl+x",
    "command": "macros.cutLines",
    "when": "!editorHasSelection"
  },

To get VS Code to recognize the command I had to add uninstall and reinstall the "macros" extension. I presume adding the entries and then installing it for the first time would produce the same result.

For debugging purposes, here is a screenshot of my keybindings for "Ctrl+x" when I had everything working the way I wanted. Compare yours by typing "Open Keyboard Shortcuts" into the command prompt and searching for "Ctrl+x".

enter image description here