Visual Studio:快捷键:重复行 [英] Visual Studio : short cut Key : Duplicate Line
问题描述
Visual Studio 2008中是否存在 重复行 命令的快捷方式?
Is there a shortcut for Duplicate Line command in Visual Studio 2008?
一些类似的例子:
- 在 Notepad ++ ,我可以使用 Ctrl + D 复制当前行
- 在 EditPlus : Ctrl + J
- 在 NetBeans 中: Ctrl + Shift + ↓ /↑
- 在 Eclipse , Ctrl + Alt + ↓ /↑
- 在 Vi/Vim , yy p
- 等
- in Notepad++, I can duplicate the current line with: Ctrl+D
- in EditPlus: Ctrl+J
- in NetBeans: Ctrl+Shift+↓/↑
- in Eclipse, Ctrl+Alt+↓/↑
- in Vi/Vim, yyp
- etc.
推荐答案
在Visual Studio 2019中
Ctrl + D
Ctrl + D
(edit)此功能现在已在VS2017中内置: Ctrl + E , V 如果未选择任何内容,则会复制一行,或重复选择.您可以将其分配给其他组合键,也可以在菜单中找到它:
(edit) This feature is now built-in in VS2017: Ctrl + E, V duplicates a line if nothing is selected, or duplicates selection. You can assign it to a different key combination, or find it in the menu:
See this reference for more information.
如@cand所述,您只需执行 Ctrl + C 即可; Ctrl + V .
As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.
Ctrl + C 将复制该行.
如果您想实施一个更完整的解决方案,或者创建一个更简单的键盘快捷键,或者不想影响剪贴板,请参见本指南:
If you'd like to implement a more complete solution, perhaps to create a simpler keyboard shortcut or you don't want to effect the clipboard, see this guide:
Visual Basic:
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
要创建宏,只需转到宏资源管理器 (工具-> Macros-> Macro Explorer"或 Alt + F8 ),然后将代码复制粘贴到 一个新模块.现在,只需为其分配键盘快捷键即可:
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:
- 转到工具"->选项" ...
- 在环境"下,单击键盘"
- 在显示包含的命令"文本框中,输入重复"(根据您给模块指定的名称).
- 您现在应该在下面的列表中看到宏
- 从使用新的快捷方式"列表中选择文本编辑器"
- 在按快捷键"文本框中设置焦点,然后按您希望用于键盘的组合键( Ctrl + Shift + D 中 我的情况)
- 点击分配"按钮
- 您现在应该在所选命令的快捷方式"文本框中看到该快捷方式
- 点击确定"按钮
- 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 whish 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
就是这样.享受吧!
这篇关于Visual Studio:快捷键:重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!