Ctrl + E, V
Ctrl + D
Ctrl + D
(edit) 此功能现在内置于VS2017中:Ctrl + E, V会复制一行,如果没有选择内容,则会复制当前光标所在行。你可以将其分配给不同的快捷键组合,或在菜单中查找:
有关详细信息,请参见此参考资料。
如@cand所提到的,您只需执行Ctrl + C;Ctrl + V即可复制该行。
如果没有选择任何内容,Ctrl + C会复制当前光标所在行。
如果您想要实现更完整的解决方案,可能是为了创建更简单的键盘快捷方式或者不想影响剪贴板,请参见此指南:
Visual Basic:
Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module DuplicateLastLineModule Sub DuplicateLine() Dim line As String DTE.ActiveDocument.Selection.StartOfLine(0) DTE.ActiveDocument.Selection.EndOfLine(True) line = DTE.ActiveDocument.Selection.Text DTE.ActiveDocument.Selection.EndOfLine() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.StartOfLine(0) DTE.ActiveDocument.Selection.Text = line End Sub End Module
创建宏,只需转到宏浏览器(“工具->宏->宏浏览器”或Alt+F8),并将代码复制粘贴到新模块中。现在只需为其分配键盘快捷键:
- 转到“工具->选项…”
- 在“环境”下,单击“键盘”
- 在“显示包含命令”的文本框中输入“duplicate”(根据您给模块的名称而定)。
- 现在您应该能在下面的列表中看到宏
- 从“在新快捷方式中使用”列表中选择“文本编辑器”
- 在“按键组合”文本框中设置焦点,并按下您希望为其使用的键盘组合(在我的情况下是Ctrl+Shift+D)
- 点击“分配”按钮
- 现在您应该能在“所选命令的快捷键”文本框中看到快捷方式
- 点击确定按钮
就是这样。享受吧!
<div>Profile.UserName: <%=Profile.UserName %></div>
- 使用这个宏复制这行后,它就变成了这样:<div>Profile.UserName: <%=Profile.UserName %></div> %></div>
。你可以看到,最后部分被“重复”了。当里面没有服务器端代码块时,它能正常工作。你知道如何解决这个问题吗?顺便说一句,我还经历了另一个有趣的事情,就是这个宏相对“慢”,这一点我没想到... :) - Sk8erPeter有一个免费的扩展程序可供下载,可以在不替换剪贴板内容的情况下复制行。您可以从这里下载。
默认情况下,它绑定到Alt + D,但是您可以通过转到"工具->选项->环境->键盘"来更改快捷键。在搜索框中键入"Duplicate",然后查找"Edit.DuplicateSelection"并编辑快捷方式为所需快捷键。我喜欢使用Ctrl+D以保持与其他编辑器的一致性。
使用简单的快捷键 Ctrl+C 和 Ctrl+V 可以实现内容复制和粘贴。如需在 Visual Studio 中复制当前行,只要不选定任何文本,在光标所在行按下 Ctrl+C 即可。此外,您还可以通过链接了解更多信息。
Ctrl + C + V 组合键在没有扩展插件的情况下,可以在 VS2012 上使用。
Ctrl + D 是在使用 Resharper 插件时在 VS2012 中的热键组合。
这是一个基于Wael发布的链接上的宏的改进版,改进如下:
Imports System
Imports EnvDTE
Imports EnvDTE80
Public Module Module1
Sub DuplicateLine()
Dim sel As TextSelection = DTE.ActiveDocument.Selection
sel.StartOfLine(0) '' move to start
sel.EndOfLine(True) '' select to end
Dim line As String = sel.Text
sel.EndOfLine(False) '' move to end
sel.Insert(ControlChars.NewLine + line, vsInsertFlags.vsInsertFlagsCollapseToEnd)
End Sub
End Module
如果你喜欢使用CTRL+ALT+UP或CTRL+UP+DOWN来复制Eclipse风格的行(或块),下面是我为此目的发布的宏:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module DuplicateLineModule
Sub DuplicateLineDown()
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
lineNumber = selection.TopLine
line = selection.Text
selection.MoveToDisplayColumn(selection.BottomLine, 0)
selection.EndOfLine()
selection.Insert(vbNewLine & line)
End Sub
Sub DuplicateLineUp()
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
lineNumber = selection.BottomLine
line = selection.Text
selection.MoveToDisplayColumn(selection.BottomLine, 0)
selection.Insert(vbNewLine & line)
selection.MoveToDisplayColumn(lineNumber, 0)
End Sub
End Module