Skip to content

Latest commit

 

History

History
36 lines (22 loc) · 1.77 KB

snippets.md

File metadata and controls

36 lines (22 loc) · 1.77 KB
title author ms.author ms.date ms.topic ms.assetid
Code Snippets
asb3993
amburns
04/14/2017
article
0FE27C0C-A861-4133-A74E-8D0505CF5342

Code snippets

Code snippets, often referred to as code templates, are useful for efficient programming as they allow the insertion and editing of pre-written blocks of code. Using code snippets can be particularly convenient for quickly adding common patterns, or even for learning new patterns when as the developer you are unsure of syntax. There are templates provided for C#, F#, HTML, XML, Python, and Razor.

This section will explain how to create, insert, and use snippets in code.

Inserting a snippet

There are some different ways to add code snippets, some of which are described below:

  • Tab Expansion - Start typing the template name, select it from the list and press TAB TAB to add it:

    Tab Expansion in Code

  • Toolbox - Use the toolbox pad to display a list of all code snippets. Drag any template from the toolbox into the correct position in the source code:

Code snippets in Toolbox

  • Insert Templates command - There is currently no default key binding set for inserting a template. To create one, browse to Visual Studio > Preferences... > Key Bindings and search for template. This allows adding the desired key binding into the Edit Binding field, then click Apply:

Inset Template command

Creating a new template

While there are many existing templates in a variety of languages that you can use and edit, new templates can also be added by navigating to Visual Studio > Preferences > Text Editor > Code Snippets:

Inset new template