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

一些类似的例子:

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


当前回答

简单的Ctrl + C;Ctrl + V,检查一下 链接。只要你不选择任何文本,当你按Ctrl+C时,这将复制光标所在的行。

其他回答

在Visual Studio 2022中

Ctrl + E, V

在Visual Studio 2019中

Ctrl + D

在Visual Studio 2017 (v15.6及以后版本)中

Ctrl + D

在Visual Studio 2017 (pre v15.6)

(编辑)这个功能现在是内置在VS2017: Ctrl + E, V复制一行,如果没有选择,或重复选择。你可以将它分配给不同的键组合,或者在菜单中找到它:

有关更多信息,请参阅此参考资料。

Pre VS2017,内置方法使用剪贴板

正如@cand提到的,你可以按Ctrl + C;Ctrl + V。

如果没有选择,Ctrl + C将复制该行。

宏观解决方案(VS2017前期)

如果你想实现一个更完整的解决方案,也许是创建一个更简单的键盘快捷键,或者你不想影响剪贴板,请参阅以下指南:

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 To create the macro, just go to the macro explorer ("Tools->Macros->Macro Explorer" or Alt+F8) and copy paste the code in a new module. Now just assign a keyboard shortcut to it: go to Tools->Options... under Environment, click Keyboard in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.) you should now see the macro in the list below choose "Text Editor" from the "Use new shortcut in" list set focus in the "Press shortcut keys" textbox and hit the combination on the keyboard you wish to use for it (Ctrl+Shift+D in my case) hit the "Assign" button you should now see the shortcut in the "Shortcuts for selected command" textbox hit the OK button And that's it. Enjoy!

我不知道这是否存在于Visual Studio 2008,但在Visual Studio 2010+你可以很容易地做到这一点:

不要选择任何东西,然后按Ctrl + C,然后(不做任何其他事情)按Ctrl + V

为什么要用这么长的方法来完成这么简单的事情?它需要不到一分钟的时间从微软下载和安装扩展。该页面说它将默认绑定到ALT+D,但对我来说,它在Visual Studio Community 2015中自动绑定到CTRL+D,没有任何更改。

这里是从Microsoft.com下载扩展的链接。

我一直在使用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 " / > ...

你必须运行你的文本编辑器与管理权限,否则它不会工作!希望这能帮助那些突然有宏功能的人。

把你的鼠标放在一行复制,然后按CTRL+C,然后按CTRL+V在同一行。 就像魔法一样:-)