How to Insert Current Date or a Specific comment assigned to any shortcut key in visual studio

1.9k Views Asked by At

How to Insert Current Date or a Specific comment assigned to any shortcut key in visual studio e.g :

I Write PD and Press Tab then it will write // Created By Danyal on 6/17/2015(Current Date)

Note : I want it in Visual Studio 2012 I have tried Snippet but failed to Get result.

1

There are 1 best solutions below

2
On

This is for VS2010 (yep, i know you wanted 2012, but as i've said, not sure it works any more). I've circulated it in one of my jobs some years ago, and found it was a great help.

Sorting through some things and lamenting about the usual lack of documentation, I thought about sharing this magic.

In the end, ALT+1, will insert comment line with your name and date, and ALT+2 will insert a TODO with your name and date.

Benefits: everybody will know what and when happened, and all it takes is 2 keys :)

enter image description here

Edit the vs editor:

enter image description here

At the end (just before the “End Module”), add these, and change NAME to your name

Sub NewCommentLinePersonal()

    Dim textSelection As EnvDTE.TextSelection



    textSelection = DTE.ActiveWindow.Selection

    textSelection.NewLine()

    textSelection.Insert(Utilities.LineOrientedCommentStart())

    textSelection.Insert(" **NAME**, " + Date.Now.ToShortDateString + ":")

End Sub



Sub NewCommentLineTodoPersonal()

    Dim textSelection As EnvDTE.TextSelection



    textSelection = DTE.ActiveWindow.Selection

    textSelection.NewLine()

    textSelection.Insert(Utilities.LineOrientedCommentStart())

    textSelection.Insert(" TODO: **NAME**, " + Date.Now.ToShortDateString + ":")

End Sub

Save and close the editor.

Goto : Tools -> Options…

Type: Personal in the “Show commands containing”:

enter image description here

And then assign ALT+1 and ALT+2 ( or whatever pleases you).

Done.