Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 243
James L. Avatar asked Jun 09 '12 07:06

James L.


People also ask

How do you copy a line without selecting it?

CTRL+SHIFT+X copies the current line without having to select it. My similar question is "How to Delete entire current line (appearing multiline with word-wrap on) without selecting it first?

How do I copy a line down in Visual Studio?

in EditPlus: Ctrl + J. in NetBeans: Ctrl + Shift + ↓ / ↑ in Eclipse, Ctrl + Alt + ↓ / ↑ in Vi/Vim, yy p.

How do you copy multiple lines in Visual Studio?

Copy Multiple Values from the Visual Studio Editor. Selected Editor Text can be copied using "Ctrl + 0", "Ctrl + 1" ... "Ctrl + 9" (For Windows)


2 Answers

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
like image 61
k0stya Avatar answered Sep 29 '22 12:09

k0stya


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

like image 25
B.O.B. Avatar answered Sep 29 '22 11:09

B.O.B.