Friday, May 31, 2013

Tip 2.40: You can insert a snippet by pressing Tab Tab

"Visual Studio Tips, 251 ways to improve your Productivity in Visual Studio", courtesy of 'Sara Ford'

Sara Ford's Blog



Sara Aside

A few months ago, she had dinner with some Microsoft MVPs and other Visual Studio users who were on campus for the Microsoft certification exams. One of the developers said, "Hey Sara, you need to blog about Snippet Tab Tab." She was blown away. She had tested this feature inside and out and never had heard of "Tab Tab." It turns out that he was just referring to the sequence of keystrokes you use to insert a snippet, but she never even thought to refer to it as the "Tab Tab" feature.


She's not a C# developer. She spent the majority of her time writing code in Visual Basic during her software testing days. Whenever she needs to use C#, she heavily relies upon code snippets because she doesn't recall the syntax off the top of her head. When in the appropriate place in the editor, you can type in the keyboard shortcut of a snippet, like for.



In this state, you can simply press Tab twice to insert the snippet. Why twice? Press it once to autocomplete statement completion. If you just type f for "for", and for is highlighted, you can just press Tab once to complete the word for. Press it twice to generate the snippet, since the cursor will be at the end of the word for in the editor.



And the moral of the story is " Tab Tab."

Happy Programming! =)
Posted by Nils-Holger at 12:24 PM with 445 comments.

Thursday, May 30, 2013

Tip 2.39: You can insert a code snippet via its shortcut keyword

"Visual Studio Tips, 251 ways to improve your Productivity in Visual Studio", courtesy of 'Sara Ford'

Sara Ford's Blog



Code snippets have the support to be given a "shortcut," usually an abbreviated version of the code snippet name that you can type into the editor and hit Tab to insert. To insert, simply type in the name of the snippet—for example, for—and then hit Tab. Note that if statement completion is open, you'll have to hit Tab twice to insert the snippet. In Visual Studio 2005, 2008 and 2012, you'll be able to see C# Code Snippet shortcuts in the statement completion window. The following screen shot is the for snippet displayed within the statement completion window. Note the snippet icon to the left.



In both Visual Studio 2008 and 2012, you won't see Visual Basic snippets in the statement completion window, but you will see a note in the ToolTip when you can hit Tab twice to insert the corresponding snippet.



Happy Programming! =)
Posted by Nils-Holger at 12:17 PM with 444 comments.

Wednesday, May 29, 2013

Tip 2.38: You can use Ctrl+K, Ctrl+X to insert a code snippet

"Visual Studio Tips, 251 ways to improve your Productivity in Visual Studio", courtesy of 'Sara Ford'

Sara Ford's Blog



The keyboard shortcut to insert a code snippet is Ctrl+K, Ctrl+X. It is bound to the command Edit.InsertSnippet, in case your mileage varies, depending on your configuration settings. She's going to use C# for this tip, but this tip applies to all languages that support code snippets. When she invokes the Edit.InsertSnippet command, the code snippet insertion UI pops up. The real tip here is that the snippet picker allows for type-ahead selection. Note how she started typing "#re" on the line. (Oh, the fun she had testing this . . . but she digresses.)



Additional keystrokes:
  • You can hit Tab to autocomplete the word. If the word happens to be the code snippet (and not a folder), pressing Tab will insert it.
  • You can also hit Shift+Tab to navigate back to the previous word (her contribution to the insertion UI).


Happy Programming! =)
Posted by Nils-Holger at 12:11 PM with 479 comments.