Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn Off Whole Line Copy in Visual Studio Code

I'm trying to disable the function in Visual Studio Code where if you don't have a selection highlighted, ctrl+c copies the entire line. I have never tried to do this on purpose, but I am always doing it accidentally when I hit ctrl+c instead of ctrl+v.

Here's what I have tried, which seems like it should work:

Under File->Preferences->Keyboard Shortcuts, there is the default setting:

{ "key": "ctrl+c", "command":  "editor.action.clipboardCopyAction",                    "when": "editorTextFocus" }, 

I have attempted to change this, so that it only copies when something is selected, by placing the following in my keybindings.json file:

{ "key": "ctrl+c",  "command": "-editor.action.clipboardCopyAction"}, { "key": "ctrl+c",  "command": "editor.action.clipboardCopyAction",                     "when": "editorHasSelection" } 

I think this should clear the previous binding before re-binding the copy action to only function when something is actually selected. HOWEVER, it doesn't work. The editor still copies a whole line when nothing is selected. If I only have the first line in there, it successfully removes the binding completely, so I know it's doing something, but the "when" tag doesn't seem to be functioning the way it should.

Is there any way to get the editor to do what I want?

like image 468
August Schack Avatar asked Sep 04 '16 22:09

August Schack


2 Answers

In Settings enter the following line:

"editor.emptySelectionClipboard": false 

That should do exactly what you want.

like image 126
Das Jott Avatar answered Oct 06 '22 20:10

Das Jott


Because this comes up on Google as a popular answer...

FYI this is also now a setting in the Settings GUI, search the settings for "empty selection" and it'll narrow it down. Untick to disable and praise your chosen deity.

like image 28
MDBenson Avatar answered Oct 06 '22 19:10

MDBenson