在Visual Studio 2008中有复制行命令的快捷方式吗?
一些类似的例子:
在notepad++中,我可以用Ctrl+D复制当前行 在EditPlus中按Ctrl+J 在NetBeans中:Ctrl+Shift+↓/↑ 在Eclipse中,按Ctrl+Alt+↓/↑ Vi/Vim, yyp 等。
在Visual Studio 2008中有复制行命令的快捷方式吗?
一些类似的例子:
在notepad++中,我可以用Ctrl+D复制当前行 在EditPlus中按Ctrl+J 在NetBeans中:Ctrl+Shift+↓/↑ 在Eclipse中,按Ctrl+Alt+↓/↑ Vi/Vim, yyp 等。
当前回答
如果你喜欢使用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
其他回答
我一直在使用Wael发布的宏:Visual Studio的重复行命令,但它一周前就停止工作了,我猜是因为Windows更新。 我是正确的,在2014年2月,宏在VS2010(和2008显然)已经被禁用。
要解决这个问题,您要么必须卸载安全更新,要么向配置文件中添加一行代码,如下所示。
在64位的Windows机器上,这些文件的默认路径是:
C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsaenv10.exe.config C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config ... < >配置 运行时> < < AllowDComReflection启用= " true " / > ...
你必须运行你的文本编辑器与管理权限,否则它不会工作!希望这能帮助那些突然有宏功能的人。
对于那些在2008年之后还在Visual Studio上查看这个问题的人,一个真正的编辑。副本已添加:
CTRL + E, V Ctrl + d (vs 2017 15.6+)
为什么要用这么长的方法来完成这么简单的事情?它需要不到一分钟的时间从微软下载和安装扩展。该页面说它将默认绑定到ALT+D,但对我来说,它在Visual Studio Community 2015中自动绑定到CTRL+D,没有任何更改。
这里是从Microsoft.com下载扩展的链接。
如果你有一个macos版本,cmd+shift+D可以帮你完成这项工作
Ctrl + D是VS 2017 v15.6中引入的一个新快捷键,它的作用似乎和Ctrl + E, V完全一样
Ctrl + D将复制光标所在的行,并将其插入到焦点行的正下方。如果希望复制一组特定的代码,只需在调用duplicate code命令之前选择要复制的代码部分。
它不会影响你的剪贴板
源