How to edit existing VS Code Snippets

前端 未结 5 1213
渐次进展
渐次进展 2020-11-30 04:04

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

For example when i type req+TAB i need require not requ

相关标签:
5条回答
  • 2020-11-30 04:12

    The extensions snippets can be found inside each snippet directory below:
    (if there are snippets in the extension)

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

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

    Just remember that if/when you choose to download and update the extension someday, all your personal modifications will get overwritten/replaced out with the updated version of the file. (unless of course you squirrel away your changes outside of the extension's directory...)

    Edit/Aside: Looking closely at all the copied editions already present in this directory, it appears that at least some of the extension updates keep the former version around. If this is the case, when you update an extension when a new version is released, you wouldn't need to worry about storing a copy of your modified file somewhere else; returning a file to active duty might just be as easy as a copy-paste from the old into the appropriate, newer, higher numbered directory.

    Resources/citations/acknowledgements:
    Thanks to here for helping initially pointing me towards the relevant directory.

    0 讨论(0)
  • 2020-11-30 04:17

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

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

    0 讨论(0)
  • 2020-11-30 04:21

    The suggestion item requestAnimationFrame is coming from the JavaScript language service. It's not coming from the snippets.

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

    1. Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets for that language
    2. Add this entry to the opened file javascript.json and save it

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

      "editor.snippetSuggestions": "top" 
      

    Now you get your self defined require suggestion in first place as soon as you type req in a .js file.

    0 讨论(0)
  • 2020-11-30 04:29

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

    If you want to create a global snippet, create a file named snippet_name.code-snippets

    If you want a language specific snippet, create it like php.json

    0 讨论(0)
  • 2020-11-30 04:38

    On my Windows installation the default/built-in JavaScript snippets are located in

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

    I renamed that snippet to "logx" (requires admin privileges to modify the file) and restarted vsCode and now have just my user "log" snippet.

    There are some threads about this on the issue tracker -

    • https://github.com/Microsoft/vscode/issues/10565
    • https://github.com/Microsoft/vscode/issues/48315
    0 讨论(0)
提交回复
热议问题