1

The only C/C++ extension I have is the official one from Microsoft. I do not have any other snippet/intellisense/autocompletion extension.

See below all the extensions loaded:

enter image description here

In trying to create shortcut keys/prefixes for my snippets, I would like to make sure that it does not clash with any pre-existing shortcuts/prefixes for other snippets. Is there a way to know / look through all currently available code snippets in VSCode and their shortcut keys/prefixes?

I tried to Insert Snippet via the command pallette in the hope that it would reveal all available snippets. Unfortunately, it does not list all snippets. See, for instance, below image, where this command pallette does not show the existence of a for snippet and yet inside the editor, when I type for, there is an option to add such a snippet.

enter image description here

7
  • you have snippets and code completions, a code completion can be a snippet Commented Sep 27, 2021 at 13:58
  • 1
    have you read the snippet doc page? some snippets live in extensions, workspace, global user snippets dir Commented Sep 27, 2021 at 13:59
  • Just figured out from code.visualstudio.com/docs/editor/userdefinedsnippets that Ctrl space gives an exhaustive list. I think I should just scroll through that to see if any keyword/shortcuts/prefixes are used already. Commented Sep 27, 2021 at 14:02
  • What is confusing, however, is the following: You can see the available snippets for a language by running the Insert Snippet command in the Command Palette to get a list of the snippets for the language of the current file. However, keep in mind that this list also includes user snippets that you have defined, and any snippets provided by extensions you have installed on that page. The image before this paragraph shows a for built in snippet, and yet that does NOT show up from the command pallette. Commented Sep 27, 2021 at 14:03
  • they don't update the images for each VSC update, only if you create an issue and it is a miss for a new feature Commented Sep 27, 2021 at 14:29

3 Answers 3

2

Snippets defined by extensions are stored in JSON files with the extension's contents. Open the extension's directory in the .vscode/extensions/ directory in your user home directory, and then open its package.json file (extension manifest), look for the "snippets" property, which will point to the paths of its snippet files.

Extensions can also provide snippets dynamically through the VS Code API. See also the SnippetString interface. Snippets can be provided by an extension in multiple ways, including through CompletionItems (suggestions), DocumentDropEdits, InlineCompletionItems, SnippetTextEdits, TextEdits, or TextEditor#insertSnippet. If you want to know about all those, this probably means reading source code for the extension. Some extensions even have a separation between frontend and backend, with closed-source backends (such as the Microsoft C++ extension).

To open user-level snippets, you can just open the snippet file in VS Code (use Snippets: Configure User Snippets in the command palette), and the full path can be obtained by hovering the tab handle, or in the breadcrumbs, or by using File: Copy Path of Active File.

Profiles can also have snippet files. You can find them in the snippets/ directory of the profile's storage (under .../Code/User/profiles, where ... is some platform specific path)

You can also have workspace/project snippets (snippets that only apply for a specific workspace) in the .vscode/ directory of the workspace folder with filenames ending in .code-snippets.

If you want to find out which extension contributes a specific snippet suggestion, then see How can I find out which extension contributes a specific suggestion in VS Code and whether it can be changed by a setting?.

Sign up to request clarification or add additional context in comments.

1 Comment

For C++ extension specifically, now all snippets come from language server. There is no JSON file inside the extension anymore.
0

I obtained confirmation officially from vscode-cpptools folks that C/C++ snippets are only available via Ctrl+Space autocomplete and not via Ctrl+Shift+P Command Palette.

See link to their answer here.

Comments

-2

Take a look in these folders

C:\Program Files\Microsoft Visual Studio\[20XX]\[VS_Edition]\Common7\IDE

C:\Program Files\Microsoft Visual Studio\[20XX]\[VS_Edition]\Common7\IDE\Extensions

C:\Users[Name]\AppData\Local\Microsoft\VisualStudio\XX.xx......\[LCID]

and files...

HTML Example

C:\Program Files\Microsoft Visual Studio\[20XX]\[VS_Edition]\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\HTML\html.xsd

C:\Program Files\Microsoft Visual Studio\[20XX]\[VS_Edition]\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\HTML\CommonHTMLTypes.xsd

C:\Program Files\Microsoft Visual Studio\20XX[VS_Edition]\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\HTML\xml.xsd

Snippets and extensions can be found in Tools -> Code Snippets Manager (Ctrl+K, Ctrl+B)

In the window set a program lang then select any folder in the list below. The corresponding snippet/extension path will be visible in the label Location: in this case the snippet about for loop in C++ can be found in this path c:\program files\microsoft visual studio\20XX\[vs_editon]\common7\ide\vc\snippets\[lcid]\visual c++\for.snippet; It's preferable to make a copy of all files before changing them so you don't have to repair or reinstall Visual Studio in case something doesn't work correctly.

1 Comment

VSCode (what this question is about) is different from Visual Studio IDE (what you have answered)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.