Cover image for the article Snip development time with snippets!

Snip development time with snippets!

How to create and use custom code snippets in Visual Studio to speed up development by avoiding repetitive typing.

Software EngineeringRiaan Swart3 min read

In development there is focus on cadence for delivery. We are going to cover how we can use snippets in Visual Studio to cut a bit of time down on tasks we repeat often while developing new features.

Code snippets is shortcuts you use to generate code. Like generating a class constructor or a property. For instance, by typing prop in your class, use the tab key to jump between variables for the snippet to fill in to complete the code section.

You can access this snippet feature from the Visual Studio | Tools menu and opening Code Snippets Manager. From there you can browse snippets you used before or upload your own.

Let discuss how we create our own snippet to improve our development productivity.

Snippets is xml files containing the code that will be generated when using the snippets. Here is a templated example of a Snippets file, defining a single snippet:

The `<Header>` section of the snippet contains the shortcut used and the information shown in the tooltip when making use of the snippet from Visual Studio. The shortcut must be unique and not conflict with already existing snippets.

The `<Snippet>` section contains variables we use in our code section as declarations. These variables will highlight for the user to fill in as they use the tab key in the code and fill in the default value as defined. The variables are optional and if your code section does not need it, you do not need to include it.

The code element within the snippet is the code that will generate when making use of the snippet in Visual Studio.

Below is an example of a snippet for creating properties that include the on notify property changed event (OnPropertyChanged) we make use of in application that is making use of MVVM:

Uploading the above snippet in the snippet manager will allow us to access the generated code section by typing promv and making use of the tab key to navigate the variables and define them. The result is a full property with a private variable and include the OnPropertyChanged() event needed for MVVM.

So, what is some more use cases for snippets?

We can use snippets to generate code that performs like a copy and paste, and then rename the values in it. When taking those code sections and making use of variables for the name changes, we can make use of snippets to generate the code for us.

We can use snippets for components that has the same constructor and methods, overridden, to generate the code that we know is normally used when defining a class.

We use snippets to generate code sections when doing a presentations to other developers, instead of copying code from a notepad.

Happy snipping!

Enjoy creating your own snippets and improving your development time by avoiding typing up repeating code. The three examples above are available on GitHub:

[https://github.com/Mecerburn/snippetsexcample](https://github.com/Mecerburn/snippetsexcample).

_This article was written by Riaan Swart from the_ [_Innovation and IoT_](https://www.firsttech.digital/innovation-iot) _team in First Technology Digital. Riaan is a technical lead at First Digital and share his passion for coding with other software developers in the First Digital Innovation Team._

Keep reading

More thought leadership.

Automation & Integration1 min read

Stop trying to build one genius agent

Everyone wants the one super-agent. It falls over. The teams winning with agents in 2026 build small crews of specialists with a manager.

Read article
AI1 min read

Most agentic AI projects will be quietly cancelled. Don’t be one of them

Gartner expects over 40% of agentic AI projects to be cancelled by 2027. The survivors share one dull trait: they chase value, not novelty.

Read article
AI2 min read

The day your AI stopped answering and started doing

Generative AI answered questions. Agentic AI takes action. When a wrong move books the flight or issues the refund, autonomy needs a blast radius.

Read article

Get in touch

Got a problem worth solving?
Let’s talk.

Send us the gist of what you are trying to do. The right person from First Digital will be in touch within a working day.