Share via


How to: Insert IntelliSense Code Snippets

You can insert IntelliSense Code Snippets using the Code Snippet Picker or typing the shortcut name of the snippet and pressing Tab. When you know the name of the snippet you want to insert, you can do so by typing its shortcut followed by the TAB key. When you have to browse for an appropriate snippet, you can use the snippet picker, which gives you categorized lists of snippets to choose from.

After you insert the code snippet, you modify it to work in your application. For example, you may find that a particular snippet inserts a new method in your application. If you inserted this new method inside an existing method, you would have to delete some extra lines of code to fix the compiler errors. You might also want to change any messages to the user or file names found in the snippet. For more information, see How to: Customize Snippet Code Once It Is Inserted into Your Code.

To use code snippets through the Insert Code Snippet Menu (C# and VB)

  1. In a C# or VB project, open a code file and put the cursor where you want to insert the code snippet.

  2. Bring up the code snippet menu in one of three ways:

    1. Press CTRL+K, CTRL+X.

    2. On the Edit menu, point to IntelliSense, and then click Insert Snippet.

    3. Right-click the mouse and then select the Insert Snippet command on the shortcut menu.

  3. Select the code snippet from the code snippet inserter and then press TAB or ENTER, or double-click the snippet.

Note

If you type the first few letters of the snippet, your selection will be moved down to that point in the list.

To use code snippets through the snippet’s shortcut

  1. In a C# or VB code file, put the cursor where you want to insert the code snippet.

  2. Type the shortcut for the code snippet that you want to add to your code.

    OR –

    Type the first few letters of the shortcut and then press either CTRL+SPACE (C#) or a question mark followed by the TAB key (VB) to view the completion list, and then select the snippet shortcut from the list.

Note

In Visual C#, snippets share the IntelliSense menu with types, members, and other auto-complete items. In Visual Basic, snippets appear on their own list.

  1. Press the TAB key once for Visual Basic or twice for C Sharp to invoke the code snippet.

Note

This procedure can only invoke snippets that have non-null Shortcut Element (IntelliSense Code Snippets). To view a snippet's shortcut element in the Code Snippets Manager, click Code Snippets Manager on the Tools menu.

See Also

Reference

Code Snippet Picker

Creating and Using IntelliSense Code Snippets