0

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.

  • i remember it used to work in 2010, not sure if it was 2012 or 2013 in which they removed the functionality , which was a shame ... – Noctis Jun 17 '15 at 11:47
  • what you are asking for is a snippet but current date is not available through snippet. For that you need to build a macro and assign to a keyboard shortcut. you can use `Alt + F8` to open the macro commands – Franck Jun 17 '15 at 11:47
  • As far as i know, it is not possible with snippets, only item templates – Alen Genzić Jun 17 '15 at 11:47
  • @Franck Macro's are not available in vs2012, any other way ?! – Danyal Manzoor Jun 17 '15 at 12:04
  • Didn't realize this was around: http://stackoverflow.com/questions/12062515/can-i-record-play-macros-in-visual-studio-2012-2013-2015 – Noctis Jun 17 '15 at 21:41
  • And if you want to vote to get it back: https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2650757-bring-back-macros – Noctis Jun 17 '15 at 21:43

1 Answers1

0

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.

Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82