Search code examples
visual-studio-2010copy-paste

Turn Off Whole Line Copy in Visual Studio


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?


Solution

  • 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