How to edit existing VS code snippets

Is there a way to remove or modify some default code snippets in Visual Studio CODE?

For example, when I type req + TAB, I need not require requestAnimationFrame

+20
source share
5 answers

The requestAnimationFrame clause comes from a JavaScript language service. This does not come from fragments.

However, you can define your own fragments and tell Visual Studio Code to show the fragments first. How to do it:

  • Go to File -> Preferences -> User Snippets and select JavaScript to edit snippets for this language.
  • Add this entry to the open javascript.json file and save it

     "require": { "prefix": "req", "body": [ "require" ], "description": "Add 'require'" } 
  • Add the following line to your preferred settings.json (user or operational parameters) and save it

     "editor.snippetSuggestions": "top" 

Now you get your own require definition in the first place as soon as you enter req in the .js file.

+20
source

Extension fragments can be found in each fragment directory below:
(if there are fragments in the extension)

Mac / Linux: $HOME/.vscode/extensions/
Windows: %USERPROFILE%\.vscode\extensions/

Select the extension you want to change, and then plunge into the javascript.json file in the snippets / directory there, and change whatever you want.

Just remember that if / when you ever decide to download and update the extension, all your personal changes will be overwritten / replaced by the updated version of the file. (unless, of course, you make your changes outside the extension directory ...)

Edit / aside : Upon careful examination of all copied releases already present in this directory, it turns out that at least some extension updates retain the previous version. In this case, when you update the extension when a new version is released, you do not need to worry about saving a copy of your modified file somewhere else; Returning the file to active mode can be as simple as copy-pasting from the old to the corresponding, newer directory with a higher number.

Resources / Quotes / Confirmation:
Thanks here for help initially pointing me to the appropriate directory.

+16
source

In my Windows installation, the standard / inline JavaScript fragments are in

C: \ Program Files (x86) \ Microsoft VS Code \ resources \ app \ extensions \ javascript \ snippets \ javascript.json

I renamed this snippet to "logx" (requires administrator privileges to modify the file) and restarted vsCode, and now I only have my custom snippet "log".

There are some topics about this on the problem tracker -

+4
source

On my Windows10 computer, the default log and other javascript snippets can be found in:

C:\Users\$USER\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json

+1
source

I found mine in ~/.config/Code/User/snippets

If you want to create a global fragment, create a file called snippet_name.code-snippets

If you want a php.json fragment of a specific language, create it as php.json

0
source

Source: https://habr.com/ru/post/1258407/


All Articles