在Visual Studio 2008中有复制行命令的快捷方式吗?

一些类似的例子:

在notepad++中,我可以用Ctrl+D复制当前行 在EditPlus中按Ctrl+J 在NetBeans中:Ctrl+Shift+↓/↑ 在Eclipse中,按Ctrl+Alt+↓/↑ Vi/Vim, yyp 等。


当前回答

不是答案,只是一个有用的补充: 作为免费赠品,我刚刚发明了(嗯……记得不能用调整由Lolo发布的代码)RemoveLineOrBlock宏。享受吧!

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module RemoveLineOrBlock

    Sub RemoveLineOrBlock()
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        Dim lineNumber As Integer
        Dim line As String

        If selection.IsEmpty Then
            selection.StartOfLine(0)
            selection.EndOfLine(True)
        Else
            Dim top As Integer = selection.TopLine
            Dim bottom As Integer = selection.BottomLine

            selection.MoveToDisplayColumn(top, 0)
            selection.StartOfLine(0)

            selection.MoveToDisplayColumn(bottom, 0, True)
            selection.EndOfLine(True)
        End If

        selection.LineDown(True)
        selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn,True)

        selection.Delete()

        selection.MoveToDisplayColumn(selection.BottomLine, 0)
        selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)

    End Sub

End Module

其他回答

您需要的命令是Edit.Duplicate。它被映射到CtrlE, CtrlV。这不会覆盖你的剪贴板。

Visual Studio Code: 2020年5月(版本1.46) Shift +向上/向下箭头:复制代码行

Ctrl + D是VS 2017 v15.6中引入的一个新快捷键,它的作用似乎和Ctrl + E, V完全一样

Ctrl + D将复制光标所在的行,并将其插入到焦点行的正下方。如果希望复制一组特定的代码,只需在调用duplicate code命令之前选择要复制的代码部分。

它不会影响你的剪贴板

虽然我意识到这不是一个键盘快捷键,但我想我应该添加这个,因为它不需要使用剪贴板,可能会帮助到一些人。

突出显示要复制的行。 按控制,鼠标单击突出显示的文本,并拖动到您想要去的地方。它将复制突出显示的文本。

针对Visual Studio 2012、2013、2015、2017,点击链接下载扩展

https://marketplace.visualstudio.com/items?itemName=ctlajoie.DuplicateSelection

现在进入工具>选项>键盘,在搜索框中输入“复制”(完整的命令字符串是“Edit.DuplicateSelection”)。在这里,您可以以与其他命令相同的方式将其绑定到任何快捷方式。