#020 HOW TO CREATE AL SNIPPETS IN VISUAL STUDIO CODE

Skip to content

#020 HOW TO CREATE AL SNIPPETS IN VISUAL STUDIO CODE

Snippets are templates of code to optimize our work when programming in Visual Studio Code. After installing the AL Language extension, you get the common list of available Snippets as for example: tcodeunit, tfield, ttable. But what if you want to build your own Snippets? In this article we will explain how to do it.

 

To create a new Snippet, you can follow the steps below:

1. Go to File > Preferences > User Snippets

Go to File-Preferences-User Snippets

2. Select New Global Snippets file

Select New Global Snippets file

3. Give a name to your Snippet file

Give a name to your Snippet file

4. A new file will be created, and it will be possible to define the Snippet structure in there. It must contain a prefix, which is the name that you will use to select your Snippet when coding, and a body, where you will write the Snippet itself.

After saving the Snippet, it can be used in the code, like in the example below:

After saving the Snippet, it can be used in the code, like in the example below

5. The structure of the new table is automatically populated with the Snippet definition.

The structure of the new table is automatically populated with the Snippet definition.

The Snippet files are stored, by default, in the following folder:

C:\Users\UserName\AppData\Roaming\Code\User\snippets

In case you want to share or copy a Snippet, you can do it accessing the folder directly.