Duplicate line command for Visual Studio

.NET, Visual Studio 3 Comments »

Visual Studio 2005One 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.

Visual Basic:
  1. Imports System
  2. Imports EnvDTE
  3. Imports EnvDTE80
  4. Imports System.Diagnostics
  5.  
  6. Public Module DuplicateLastLineModule
  7. Sub DuplicateLine()
  8. Dim line As String
  9. DTE.ActiveDocument.Selection.StartOfLine(0)
  10. DTE.ActiveDocument.Selection.EndOfLine(True)
  11. line = DTE.ActiveDocument.Selection.Text
  12. DTE.ActiveDocument.Selection.EndOfLine()
  13. DTE.ActiveDocument.Selection.NewLine()
  14. DTE.ActiveDocument.Selection.StartOfLine(0)
  15. DTE.ActiveDocument.Selection.Text = line
  16. End Sub
  17. 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:

  1. go to Tools->Options...
  2. under Environment, click Keyboard
  3. in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.)
  4. you should now see the macro in the list below
  5. choose "Text Editor" from the "Use new shortcut in" list
  6. 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)
  7. hit the "Assign" button
  8. you should now see the shortcut in the "Shortcuts for selected command" textbox
  9. 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
 

ASP.NET newbie

.NET No Comments »

With the departure of one of our ASP.NET co-workers, I decided to start learning ASP.NET and the whole Visual Studio .NET story. So I installed VS.NET, SQL Server and all that was needed and was about to create my first C# ASP.NET application when...

Visual Studio .NET has detected that the specified Web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications or services

... I just installed all the software, updated the .NET framework and then this? I was about to uninstall the whole thing and head over to Eclipse for some FAME pleasure ;-), but then decided to "google" for a solution and was more than happy to find one fast. So here it is.

- Open Visual Studio Command prompt., via Start-> Programs -> VS.NET 2003 -> Tools -> Command Prompt
- Type “aspnet_regiis -i“ and press enter.

The output should be:

c:\>aspnet_regiis -i
Start installing ASP.NET (1.1.4322.0).
Finished installing ASP.NET (1.1.4322.0).

And now back to Visual Studio for some C#'n.
Also, if anyone has some interesting links to ASP.NET resources, feel free to leave them in the comments.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login