40

In visual studio code, if you press ctrl + c on a blank line, with nothing highlighted, it copies the blank line.

I thought there may was an option to disable this, but haven't been able to find it.

2
  • 1
    There is an option in (regular) Visual Studio for "Apply Cut or Copy commands to blank lines when there is no selection." I don't know if VSCode has a similar option, but that's some text you might look for.
    – BJ Myers
    Commented Mar 3, 2017 at 20:31
  • I wanted the opposite of the OP. The setting editor.emptySelectionClipboard: true works, but not when the vim extension is enabled :-( Commented May 3, 2017 at 23:14

2 Answers 2

66

You should be able to do this by configuring the option editor.emptySelectionClipboard to false.

6
  • 3
    "editor.emptySelectionClipboard": false Works GREAT! :)
    – Sol
    Commented Mar 4, 2017 at 17:07
  • 13
    For me, this disables copying/cutting a line with ctrl-c/x when I have nothing selected. I only want to disable cutting lines that only contain whitespace...
    – N. McA.
    Commented Mar 22, 2017 at 22:31
  • 2
    If you don't like how the command works, you probably need to write your own extension or request an enhancement on the issues page. (I didn't write the code that implements the behavior you don't like, so it's a bit pointless to complain about it here.) Commented Aug 11, 2020 at 19:38
  • Is there a similar option in Visual Studio 2022 too? I can't find it
    – Fabio
    Commented May 16, 2023 at 15:49
  • 5
    @Fabio it's in Options->TextEditor->General "Cut or Copy the current line without selection" I don't know why anyone would ever want that to be turned on. I've accidentally duplicated lines so many times, causing build failures, just because there was no selection.
    – Eyelash
    Commented May 18, 2023 at 7:47
4

There is an extension for it: https://marketplace.visualstudio.com/items?itemName=usernamehw.do-not-copy-empty

3
  • Cool. Might as well just change the settings with it being built in and all.
    – Sol
    Commented Mar 1, 2021 at 16:17
  • cool, but this extension works only with CTRL + C, not with CTRL + X Commented Aug 30, 2021 at 22:32
  • 1
    better than changing settings cause you don't lose the "copy line" functionality Commented Jul 19, 2022 at 17:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.