Turn Off Whole Line Copy in Visual Studio

2020-07-02 21:59发布

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?

2条回答
做自己的国王
2楼-- · 2020-07-02 22:38

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

查看更多
在下西门庆
3楼-- · 2020-07-02 22:47

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
查看更多
登录 后发表回答