Saving your sanity with Snippets
- Posted: Sep 09, 2013 at 6:00AM
- 13,518 views
Last week, in honor of the Labor Day, I made a "labor saving" themed post in, Saving you some labor in creating your Unit tests... This is going to surprise you, but since I kind of like themes, today's post is going to be another labor saving themed post.
Okay, I can here you already, "How's that 'Fun,' Greg?"
Well maybe it's not fun, fun. Not robots or bleeding edge coolness, but I'll tell you what isn't fun, it's writing the same code over and over. For loops, property setters, custom code snips, common T-SQL patterns, etc. You know what I mean, that same little block of code that you might copy-n-paste-n-tweak all the time? Or that statement group you type so often you don't even have to think about it, the muscle memory is so ingrain that you can do it with your eyes close?
"Greg, give us a break, we all know about code snippets! Visual Studio has a bunch..."
You're right, it does. But everyone also knows that the ones in the box are the starting point, not the end point. The real fun starts when you start creating your own...
The Snippet Designer is a plugin which enhances the Visual Studio IDE to allow a richer and more productive code snippet experience.
Change log for 1.5.0
- Added support for Visual Studio 2013
- Fixed some typos
- Fixed SQL snippet user directory
- [GD] Visual Studio 2013
- Visual Studio 2012
- Visual Studio 2010
- Visual Studio 2008
- Access it by opening any .snippet file or going to File -> New -> File -> Code Snippet File
- It uses the native Visual Studio code editor so that you can write the snippets in the same environment you write your code.
- It lets you easily mark replacements by a convenient right click menu.
- It displays properties of the snippet inside the Visual Studio properties window.
A Snippet Explorer tool window to search snippets on your computer.
- It is located under View -> Other Windows -> Snippet Explorer
- This tool window contains a code preview window which lets to peek inside the snippet to see what it is without opening the file.
- Maintains an index of snippets on your computer for quick searching.
- Provides a quick way to find a code snippet to use, edit or delete
The real awesome part? The source is available too.
What? You're not just using Visual Studio, but also live in SQL Server 2012 Management Studio too? Think snippets there would also be nice?
T-SQL code snippets is a very handy new feature in SQL Server 2012.
Using code snippets you can save time when you write code and you just need to enter code that does common tasks. Code reuse has always been useful and it really increases productivity!
In SQL Server 2012 you can import your own custom-made snippets. However, prior to that, you need to create a snippet.
Each snippet is an XML file that specifies some header information regarding the snippet and then it includes the T-SQL code.
A sample T-SQL code snippet for SQL Server 2012 is illustrated in the following image:
Using Snippets Generator, you can generate T-SQL code snippets, save it into a directory and then add the directory, and consequently your custom snippets, into SQL Server 2012 Management Studio (SSMS) via the Code Snippets Manager! The directory's name will be the snippet category name in Code Snippet Manager and its contents will be the snippets!
You can either create a snippet from scratch or just make use of one of the snippet templates shipped with the tool in order to assist you with the design of your custom snippet.
Additionally, you can open an existing snippet generate a new one based on the original.
Oh yeah, the source for this project is available to. It's not as complex with the first, but sometimes simpler is better...