I've enabled the default "log" snippet in VS Code. I also added another snippet. Neither show up when I type their prefixes. I have set editor.tabCompletion to true.
Any idea why these don't work?
There are a couple of ways you can fix this problem. The problem is Intellisense is getting in the way or default putting your snippets at the bottom of the list.
First I played with the suggestion delay, but then I settled on having Intellisense put my snippets in the top of the list of suggestions with the snippetSuggestions user preference:
{
"editor.tabCompletion": "onlySnippets",
"editor.snippetSuggestions": "top"
}
other in editor.quickSuggestions too. I think I had disabled it because there was so much spam from some libraries I didn't care about.tabCompletion needs to be on for it to work? Great.For react with typescript, I had to specifically add 'typescriptreact' to the scope.
"scope": "javascript, typescript, typescriptreact"
javascriptreact instead of javascript in the bottom right. I had to move it to a global snippet with the scope as answered, although I had to add javascriptreact instead as I'm not using TypeScript."scope": "javascript, javascriptreact" inside javascriptreact.json (because my snippet was not applying for files with a .js extension) VSCode would warn that "Property scope is not allowed".Sometimes the obvious that gets overlooked first. Upon starting VSCode and creating a new document (Ctrl + N) it may come as a surprise that the snippets do not work. Check in the bottom right hand corner of the VSCode editor as per default a 'Plain Text' file is presented. Change the file type to your favourite language with snippets.
This may overcome some unnecessary trouble shooting ;-)
settings.json were totally fine, but my VSCode editor prejudged it as Django HTML instead. Switching it to HTML, what i needed brought the snippet functionality back."scope": "javascript,html,django-html". In this way you can continue to use your Django extension.If you are trying to insert PHP snippets, its worth noting the you must manually include the
<?php
before the snippets will start to work.
PHP, those snippets that are assigned to PHP only work when the prefix is entered within </php ... ?> tags. Kinda dumb TBH.<?php tag, in such a way to just type ph and got hinted for it. Though it doesn't work , used this stackoverflow.com/a/55220696/3446280 , I create a new PHP file and type ph or either php but it is wrong since the begin because the label is "abc" and not the square icon. The solution has been to create the snippet inside a "New global snippet file..."<?= $0 ?> then you need to add snippet to html.json, not php.json.What I actually found is that when you have a php intelliSense and you want a php tab tag to open and close, I added the extension to a html file type as well.
{
"Open php tag": {
"scope": "php, html",
"prefix": "php",
"body": [
"<?php",
" $1",
"?>"
],
"description": "Opens php tags"
}
}
This worked for me :)
I had to:
Go to settings (Windows/Linux: File > Preferences > Settings, macOS: Code > Preferences > Settings) and type in quick in search box and click Edit in settings.json:

Add
"editor.quickSuggestions": true
under the section with corresponding file type (markdown in my case):
UPDATE It could be that you need to add this:
"editor.quickSuggestions": {
"comments": "on",
"strings": "on",
"other": "on"
}
instead of just "editor.quickSuggestions": true, because the format might have changed since the time I wrote original answer. Check it for yourself and let me know.
In my case it was not working because I had a space in the name of the snippet
{
...,
"snippet name": { // it should be snippet_name. Notice the _
...
}
}
So make sure that:
{name}.code-snippets file under .vscode folderspacestypescript and typescriptreact.The extension matters when selecting scope. I had recently switched from react using .js extension to react with typescript using .tsx extension. My snippet said "javascript, typescript" so I thought I was covered, but tsx files are actually considered "typescriptreact". I changed to the following and it started working on my tsx files:
{
"Styled Component React Arrow Function With Default Export": {
"scope": "javascript, javascriptreact, typescript, typescriptreact",
"prefix": "scraf",
"body": [
"import React from 'react'",
"import styled from 'styled-components/macro'",
"",
"const Container = styled.div`",
" display: flex;",
"`",
"",
"const ${TM_FILENAME_BASE} = () => {",
" return (",
" <Container>",
" $1",
" </Container>",
" )",
"}",
"export default ${TM_FILENAME_BASE}",
],
"description": "Styled Component React Arrow Function With Default Export"
}
The hint here is you check the full name of the language that your VSCode is automatically recognizing, so after you transform all in lowercase and remove the white spaces and add it in the scope property in the snippet file.
javascript,typescript,typescriptreact in your scope settings. VSCode is showing Typescript JSX in language but adding typescriptjsx didn't work, you need typescriptreactFor those who are looking for overriding default snippet (log)
Overriding the log.json file snippet was not working for me in User Snippets (For Typescript at least).
Solution: I created a new global snippet ( File > Preferences > User Snippets > New Global Snippets file ) with a different name 'clog' (full name: 'clog.code-snippets') and prefix and it worked.
My problem was that some snippets worked, and others dont. (like: JavaScript Snippets worked well)
My issue solved when i installed a plugin that added the respective, specific filetype association (im my case: *.blade.php)
When creating UserSnippets at blade.json it worked fine.
I was trying to setup a snippet to auto add the php open and close tags into my file, as Robert Cooper noted it only worked when I was already writing inside the code specific type block.
So I set !p to load <?php$1?> whenever I use it inside an HTML block. The snippet was set into the html.json file.
In case anyone else has this issue, I was working with react native and my JavaScript snippets weren't working. I checked settings.json by going to settings, searched for quick suggestions, and then edit in settings.json.
"files.associations": {
"*.js": "javascriptreact" // This needed changed to "javascript".
}
Otherwise, you can create the snippets for javascriptreact.
For any other morons out there like me...
I had a typescript file I was using with react, so you need typescriptreact listed in your snippet.
But I was also naming my file with a .jsx extension instead of a .tsx extension which is why it wasn't showing up...
typescriptjsx but it didn't work, settings typescriptreact worked fine.not sure if anyone made the same "just messing around" mistake that I did, but the profiles(https://code.visualstudio.com/docs/editor/profiles) functionality almost did me in. I had selected a different profile from my default and everything changed. Extensions, snippets, keyboard shortcuts, and probably more I didn't notice. This is just after I was telling everyone how awesome the settings sync is. I had managed to change my profile via the gear in the bottom of the main side bar. The moment I changed back to default everything came back.
The cause of this issue is that another language is active in VS Code. Check the lower left hand corner of VS Code to change the language to the desired one. Screenshots below. enter image description here
Click on C++ then an input box will appear at the top. Type in the appropriate language, for example HTML and the issue will resolve.
Visual Studio Code How to add the <?php opening tag snippet
Just for the sake of preventing some headache to those who wants to add the handy <?php opening tag snippet
If you follow the instructions on https://code.visualstudio.com/docs/editor/userdefinedsnippets you'll got misled since you are hinted to find the wanted language in File>Preferences>User Snippets
so you type PHP and you'll edit php.json
... but this won't work, because the mechanism works ONLY AFTER the VSCode editor knows this is a PHP file and the filter at bottom right corner looks will not consider itself until you don't add a <?php at the begin of the file
no way
despite filename extension
despite you even manually set the "Select language mode" to PHP (though with PHP extension in the filename, this will be already set to PHP mode)
The unique solution I have found is to add the snippet to a "New global snippet file..."
you will find this option as first as soon you browse to File>Preferences>User Snippets
This solution is obvious ... but only after that you guess it :-) since you add this global,
in fact the snippet in global, as it suggests, will work "globally, in any type of file type
For people trying to add snippets to .jsx and .tsx
Go Code/Gear > Preferences > User Snippers
For .tsx type typescriptreact.json For .jsx type javascriptreact.json
Add your snippets there.
{"Example": {
"prefix": "$example",
"body": [
" {",
"type: example,",
"},"
],
"description": "Example"
}```
In my case, I had the following configuration value set to false, which effectively disabled all snippet suggestions via IntelliSense. Switch the setting to true to enable them again.
{
"editor.suggest.showSnippets": true
}
As others have mentioned, you can also configure where snippets should appear in your IntelliSense suggestion list by setting the property "editor.snippetSuggestions" to either top, bottom, inline or none
CTRL+P> Change Language Modeand typehtml. I have 3 listings, it wasn't working in Html, because the default was htmlliquid.