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 requestAnimationFrame
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.
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:
Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets for that language
Add this entry to the opened file javascript.json and save it
"require": {
"prefix": "req",
"body": [
"require"
],
"description": "Add 'require'"
}
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.
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
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
Attention everyone!
This is now possible in the latest vscode. Solution here: https://github.com/microsoft/vscode/issues/10565#issuecomment-721832613
That solution tells you how to disable any snippet (including built-in or extension snippets). While this is technically not editing the snippet, disabling the snippet and then creating your own user snippet accomplishes the same exact goal. Yay!
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
Hiding default VSCode snippets is easy:
you can hide specific snippets from showing in IntelliSense (completion list) by selecting the Hide from IntelliSense button to the right of snippet items in the Insert Snippet command dropdown.
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_can-i-remove-snippets-from-intellisense
Related
I'm currently writing my own language and I'm at a point where I would like to publish it to the VSCode-Marketplace so people can test it.
I have written a language extension and a syntax highlighter with the Yeoman-Generator and now want to merge it with my executable file that launches the interpreter, so that a file can get interpreted after clicking the run-code button.
I now have checked multiple articles, like:
How to add a run button in visual studio code? - StackOverflow
How to define or support a code language on Visual Studio? - StackOverflow
Debugger Extension Guide - VSCode API
However, I haven't found anything useful.
Currently, the code-runner displays the following error, when clicking on run, or pressing the shortcut:
(Code language not supported or defined.)
But even after a lot of browsing Google for adding new language support to the code-runner, I found absolutely nothing helpful.
(See this page, idk what Settings/Preferences they are referring to!?)
I also was not successful with tasks, as they don't seem to connect to the run-buttom or debug-button in any way.
My question is: How can I make the run-button execute a custom bash-command, when a file in my language is opened?
Okay, I finally did it.
For anyone wondering:
You have to go to the settings and type "code-runner" into the search bar.
Scroll down a little, and you should find the code runner-executor map.
Click on the "edit in settings.json" button.
Now a .json-file should've opened. There are two possible scenarios: Either, there is a json-object called code-runner.executorMapBy... or not.
If there is none, type code-runner.executorMapByFileExtension and let autocomplete do the job.
If the json-object exists, add the file-extension and a bash command that executes your compiler/interpreter. It gets automatically executed in the directory the program-file lies in.
Now still dont know, how to include the settings in my extension, but that was already a big step. Further help is still appreciated!
There is an open source extension called code runner, you can check source code there.
I want to create a standard VS Code snippets file for my team. We use Perforce for version control and I'd like to create a snippet file in our project folder and point VS Code to it. I just want people to be able to sync up and have them just have updated snippets.
I think Project-level snippets will do what you want:
Project level snippets
Snippets can now be scoped to a project and
shared with your team. Simply use the Preferences: Configure User
Snippets command or create *.code-snippets file in the .vscode folder.
Project snippets work just like other snippets, they show up in
IntelliSense and in the Insert Snippet action where they now have
their own category
More info: https://code.visualstudio.com/updates/v1_28#_project-level-snippets
Currently, I name my files as .py while working on them, and then change them to .sage when I need to execute. Is there a way to get the python colour scheme for sage files on VS code?
There is an extension called SAGE enterprise management that claims to do it, but the instructions are a bit unclear:
It says:
Create a x3-code named folder inside your ~/.vscode/extensions/;
Copy all files in yours recent created folder;
Reload VS Code and enjoy;
I tried both copying my sage files into the folder, and the contents of the x3-extension into the folder, both of which didn't work.
The instructions referred to in the question are for Sage the
accounting software, not for SageMath the Sage mathematics
software system.
In the case of SageMath, we need to tell VS Code to apply Python
formatting not only to files ending in .py, but also to files
ending in .sage. One way to do that is to use the "file to
language association" setting:
https://code.visualstudio.com/updates/vMarch#_file-to-language-association
One would add associations from "*.sage" to "python".
This related question has answers explaining where Visual
Studio Code's language extension files are located on macOS
and Windows:
Stack Overflow question 42498117
Following the first link provided in the prior answer, I got it worked. In details,
go to Settings, type "files.associations" in the search box for Search settings.
It shows you a list of (item, value) in which you can add a new item (*.sage, python). See my screenshot below
Hope it works for you!
I am looking for VSC extensions that will let me save my own code snippets and reuse them in any future projects with shortcuts like when I type html I am able to pick an option that generates whole document example that I can then continue modifying.
Ideally it should also have an option to export all custom settings so I can move them to another machine or back them up if I need to format the system.
I realized this was one of my major efficiency issues when I kept copying code from old projects to be reused in my latest work. I did check the extension search in VSC but so far only found such that already include existing snippet shortcuts.
I found 1 viable method so far with native VSC but post if you know of an even better way.
Press Ctrl + P and > then type Preferences: Configure user snippets and then selecting a language. To generate json fast I used: https://snippet-generator.app/
It saves snippets in AppData\Roaming\Code\User\snippets folder so that is good for backuping or exporting.
To reorder snippets to have custom ones at the top of the suggestions box for faster use go to: Workspace Settings > Text Editor > Suggestions > Snippet Suggestions and set it to top.
I've started to experiment with Visual Studio Code.
I've built up a large library of snippets managed by Yassnippet. I want to use them with VSC. A third-party developer, Mads Hartmann has published an extension that offers to connect an existing yassnippet library to VSC.
Following the instructions in the readme, I copied the following to my user settings. (This is the sole contents of my user settings)
{
"editor.tabCompletion": false,
"editor.snippetSuggestions": "none",
"yassnippet.path": "/home/me/.emacs.d/list/yasnippet/snippets"
}
This appears to be inadequate. Snippets are not being picked up.
Also, if I look under the 'Contributions' tab in the Yassnippet extensions dialogues, I can see that the setting remains set to it's default.
What do I need to do to get this extension working?
You also need to define a map between the languages and the folders inside Yassnippet.
For example, in order to include the python snippets (located inside the python-mode folder) you should add to your settings:
"yassnippet.mapping":{
"python": "python-mode"
}