23

There is a setting in Visual Studio 2010 to turn off copy and cut commands when the cursor is on a blank line and there is no selection. However, when the cursor is not on a blank line and you press ctrl+C, it always copies the entire line to the clipboard. I find this very irritating because I always highlight something first, copy it, then place the cursor where I want to paste it and press ctrl+V. However, sometimes I miss the v and hit the c, which replaces the text on the clipboard with the text of the current line and I have to start all over...

Does anyone know how to turn off copying when there is no selection, regardless of whether the cursor is on a blank line or not?

James L.
  • 9,384
  • 5
  • 38
  • 77
  • 2
    I don't know when it was introduced but in VS2019 you can press CTRL+SHIFT+V and you get a drop down list of the last 9 things copied to the clipboard, so if you accidentally lose what you copied you can still get it back quite easily! – Etherman Jan 17 '20 at 09:51

2 Answers2

16

There is the option in the settings: Go to Tools - Options -> Text Editor -> ALl Languages -> Apply Cut or Copy commands to blank lines when there is no selection

Also if you accidentally copied something into clipboard you can use following shortcut: Ctrl+Shift+V – cycle through the clipboard ring.

EDITED: It seems there is no option to turn of it because by default Ctrl-C is assigned to Edit.Copy command, which copies the current line if nothing is selected. However you can assign following macro to Ctrl-C and it should fix the issue:

Sub CopyOnlyIfSelection()
    Dim s As String = DTE.ActiveDocument.Selection.Text
    Dim n As Integer = Len(s)
    If n > 0 Then
        DTE.ActiveDocument.Selection.Copy()
    End If
End Sub
k0stya
  • 4,267
  • 32
  • 41
  • 3
    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. Thanks though for the suggestion about cycling through the clipboard ring. Didn't know that! – James L. Jun 11 '12 at 18:41
  • That is an excellent workaround. Thanks @k0stya. It is especially useful since ctrl+shft+V only works if you copy several times within the IDE; something copied from another source is not appended to the clipboard ring... – James L. Jun 19 '12 at 15:10
  • How to use this macro code in VS 2015 update 3? there are different Marco addons? Which one do I need? :| – ewerybody Jan 25 '18 at 13:55
  • I was able to do something similar using the Visual Command Plugin: https://stackoverflow.com/questions/55942005/how-to-change-ctrlc-in-visual-studio-2017-to-copy-word-not-entire-line – Daryl May 03 '19 at 20:20
1

I know this is old question, but as Macros are no longer natively supported in newer versions of Visual Studio, I thought I'd shared my new extension (cause I couldn't find any existing extensions): https://marketplace.visualstudio.com/items?itemName=KiwiProductions.CopyOnlySelection

B.O.B.
  • 704
  • 4
  • 10