78

I have somehow misconfigured fingers. This leads to a very annoying situation.

  1. I select a block of text to copy;
  2. I move the cursor the place where I want to paste the code;
  3. I accidentally press Ctrl+C again instead of Ctrl+V;
  4. My block of copied text is replaced by an empty block;
  5. I have to go back and do it all over again. Grrrrr.

Is there any way to disable this behavior, that is to disable copy of empty blocks of text in Visual Studio 2005+?

John Sheehan
  • 77,456
  • 30
  • 160
  • 194
Jorge Ferreira
  • 96,051
  • 25
  • 122
  • 132

6 Answers6

77

It's not copying an empty block, it's copying the blank line. You can change this setting in Tools > Options > Text Editor > All Languages > 'Apply Cut or Copy Commands to blank lines when there is no selection'

John Sheehan
  • 77,456
  • 30
  • 160
  • 194
  • 6
    The setting under Tools | Options only applies when the cursor is on a blank line. When the cursor is on a line with text and nothing is selected, ctrl+c still copies the current line to the clipboard – Postlagerkarte Sep 25 '14 at 09:07
  • 2
    Surely the default should be unticked! – Percy Dec 03 '18 at 08:59
  • 1
    It would take a dissertation to explain to me why this is so useful they even wasted time making it an official setting. – person27 Feb 10 '19 at 17:37
  • 1
    Consider: this also disables Ctrl+X for deleting an empty line :o/ – mike Jul 23 '19 at 10:29
  • 2
    Same solution applies for VS Code: Settings > Text Editor > Editor: Empty Selection Clipboard – Cameron Jewell Sep 23 '20 at 19:56
19

Press CTRL+SHIFT+V twice.

Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
  • this is what i do. it's nice in general, even if i have other things copied. i just cycle through my clipboard – Darren Kopp Sep 16 '08 at 16:08
  • Does this only work in VS, or is this a Windows feature? – ale10ander Jun 10 '15 at 21:09
  • 2
    @Cptn_Hammer, VS Only – Magnus Johansson Jun 12 '15 at 16:24
  • Thanks! (sorry for the necro). I use ClipCube to manage my clipboard, and I would be a little disheartened if some of that functionality already existed :p. Maybe I can add that as a global hotkey, though (in conjunction with ClipCube, perhaps.... – ale10ander Jun 12 '15 at 16:32
  • 1
    This is a great answer. Also works in SQL Server Management Studio, so I'll be looking out for other places it works too – Red May 30 '18 at 10:53
2

I'm using Visual Studio 2008 (but I believe this answer applies to Visual Studio 2005).

Select Tools -> Options.

Navigate to the "Text Editor" node and expand it.

Expand "All Languages" (or whatever language you want to apply this to) and check the "Apply Cut or Copy commands to blank lines when there is no selection".

Jeremy Wiebe
  • 3,894
  • 22
  • 31
2

The option that saved my sanity is found in Tools - Options - Text Editor - All Languages - General. There's a checkbox Apply Cut or Copy commands to blank lines when there is no selection. Unchecking this allowed me to hit Ctrl+C all i want on a blank line without losing the content on my clipboard.

Source

EndangeredMassa
  • 17,208
  • 8
  • 55
  • 79
1

For some reason that option didn't work for me (VS2010)

The answer mentioned here where you assign Ctrl+C to the macro worked however Disabling single line copy in Visual Studio

Community
  • 1
  • 1
FearlessHyena
  • 3,527
  • 33
  • 39
1

Go to Tools > Options > Text Editor > All Languages > General

The option on that page is "Apply Cut or Copy commands to blank lines when there is no selection"

dcstraw
  • 3,243
  • 3
  • 29
  • 38