One of the things I'm missing in Visual Studio is a keyboard shortcut to duplicate a line of code. I use this command alot in Eclipse/FDT (Ctrl+Shift+D) and once you get used to it, you can't live without it. After googling around for a moment, I found this VB code that does just that. The great thing is that in Visual Studio you can create your own macro and attach it to a keyboard shortcut.
-
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 assing 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 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
And that's it. Enjoy !
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
Christophe Herreman is a software developer living in Belgium. He's working on Flex based e-learning solutions at
Recent Comments