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

一些类似的例子:

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


当前回答

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

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

其他回答

在Visual Studio 2013中,可以使用Ctrl+C+V

在Visual Studio 2010中,你用CTRL + INSERT复制光标所在的整行,然后你可以用CTRL + V或SHIFT + INSERT粘贴它。

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

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

它不会影响你的剪贴板

在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!

有一个免费的扩展,你可以下载这里,让你复制行无需替换剪贴板的内容。

默认情况下,它被绑定到Alt + D,但你可以通过点击工具->选项->环境->键盘将其更改为任何你想要的。在搜索框中输入“复制”,然后查找“编辑”。DuplicateSelection”,并编辑快捷方式为任何你想要的。我更喜欢Ctrl + D与其他编辑器保持一致。