在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
其他回答
在Visual studio 2017或其他版本不需要宏或扩展,
进入“工具>选项>环境>键盘” 在显示命令下包含:写编辑。重复的 将光标置于“按快捷键:”,按“Ctrl + D”,单击“分配”按钮 单击OK保存新的键盘快捷方式
不是答案,只是一个有用的补充: 作为免费赠品,我刚刚发明了(嗯……记得不能用调整由Lolo发布的代码)RemoveLineOrBlock宏。享受吧!
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module RemoveLineOrBlock
Sub RemoveLineOrBlock()
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
selection.LineDown(True)
selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn,True)
selection.Delete()
selection.MoveToDisplayColumn(selection.BottomLine, 0)
selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
End Sub
End Module
Visual Studio Code: 2020年5月(版本1.46) Shift +向上/向下箭头:复制代码行
I use application link:AutoHotkey with below code saved in CommentDuplikateSaveClipboard.ahk file. You can edit/remove shortcuts it is easy. I have link to this file "Shortcut to CommentDuplikateSaveClipboard.ahk" in Autostart in windows. This script protect your clipboard. If you are more curious you would add shortcuts to thisable/enable script. I sometimes use very impressive Multi Clipboard script to easy handle with many clips saved on disk and use with CTRL+C,X,V to copy,paste,cut,next,previous,delete this,delete all.
;CommentDuplikateSaveClipboard.ahk
!c:: ; Alt+C === Duplicate Line
^d:: ; Ctrl+D
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{HOME}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{END}{ENTER}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return
!x:: ; Alt+X === Comment Duplicate Line
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{HOME}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{LEFT}//{END}{ENTER}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return
!z:: ; Alt+Z === Del uncomment Line
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{DEL}{HOME}{DEL}{DEL}
Clipboard := ClipSaved
ClipSaved =
return
!d:: ; Alt+D === Delete line
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{DEL}
return
!s:: ; Alt+S === Swap lines
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{UP}{END}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return
!a:: ; Alt+A === Comment this line, uncomment above
Send, {END}{HOME}//{UP}{HOME}{DEL}{DEL}
return
在Visual Studio 2010中,你用CTRL + INSERT复制光标所在的整行,然后你可以用CTRL + V或SHIFT + INSERT粘贴它。