Tryer
Tryer

Reputation: 4080

Where do code snippets reside in Visual Studio Code?

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

Upvotes: 1

Views: 2149

Answers (3)

starball
starball

Reputation: 51102

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?.

Upvotes: 2

Alison Nunes
Alison Nunes

Reputation: 165

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. And I tried to include some images but I got an error message from StackOverflow requiring me at least 10 of reputation score to post images, in fact this is so depress. I nevermore will desire to be abble to refact an IDE's code and not be abble to publish screenshots by only one reputation's point that and I never knew for what this works. But now I understand better my ex wife when she told me that I'm good for nothing.

Upvotes: -1

Tryer
Tryer

Reputation: 4080

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 Pallette.

See link to their answer here.

Upvotes: 0

Related Questions