Skip to content

[snippets] Global snippet option #13182

Closed

Description

@jreljac
  • VSCode Version: 1.5.3
  • OS Version: macOS 10.12

Currently snippets are defined by language type and only available when a file of that language is open. In an effort to not reproduce snippets between languages I'd like to see a "global" snippet .json file that makes snippets available for any file type, in addition to the file type specific ones defined in Code...Preferences...User Snippets.

Example. I've created a snippet for the CSS margin option:

"margin": { "prefix": "Z_margin", "body": ["margin: ${1:top}px ${2:right}px ${3:bottom}px ${4:left}px;${5:}"], "description": "Margin" }

I'd like to have that available for .css, .html, and .php files without haveing to copy it in all three .json files.

Activity

  1. jrieken commented on Oct 5, 2016

    @jrieken
    Contributor

    Makes sense. Needs thinking. Martin Aeschlimann (@aeschli) As the initial creator of this, ideas?

  2. added
    feature-request
    on Oct 5, 2016
  3. TheColorRed commented on Oct 5, 2016

    @TheColorRed

    Couldn't you add something like this?

    global.json

    {
        "My Awesome Snippet": {
            "prefix": "abc",
            "lang": ["css", "php", "html"],
            "body":[
                "abc123!@#"
            ]
        }
    }
  4. TheColorRed commented on Oct 5, 2016

    @TheColorRed

    Jason Reljac (@jreljac) That was just my example of implementation to answer Johannes Rieken (@jrieken) question.

  5. changed the title [-]Global snippet option[/-] [+][snippets] Global snippet option[/+] on Oct 10, 2016
  6. Ciantic commented on Apr 18, 2017

    @Ciantic

    With HTML / PHP this is particularly annoying since I would like to have my snippets working in the whole PHP file. Right now they work inside "normal" HTML parts, but not for example when I'm inside an attribute value:

    e.g.
    They work just fine inside html (when defined in html.json):

    <div>They work inside this</div>
    

    But they do not work inside an attribute:

    <div class="image" style="background-image: url('SNIPPETS DOES NOT WORK HERE');">
    

    I've tried adding my snippets to plaintext, xml etc, nothing seems to work inside attribute value.

  7. nikpushkarski commented on May 10, 2017

    @nikpushkarski

    +1 for idea of common snippets for all/chosen languages

  8. grigoryvp commented on May 10, 2017

    @grigoryvp

    Will be very useful for both multi-language stacks like PHP and VueJS, and for commenting different code with comment-related language snippets

  9. MunifTanjim commented on Jun 2, 2017

    @MunifTanjim

    For user-defined snippets, user/workspace setting could have something like this:

    /* this is not an actual implemented option... */
    snippets.extend: {
      "javascriptreact": "javascript"
    }

    which will load all the user-defined "javascript" snippets in the "javascriptreact" files.

  10. larssb commented on Jun 27, 2017

    @larssb

    I'm actually on the lookout for snippets being available on a workspace level in addition to the implementation as it is today. Here is why; Using Plaster it is easy to get the idea that snippets should be templated. However, when doing this via Plaster you avoid overwritting an potentially already existing "language".json file in the users "snippets" folder.
    In regards to precedence I think the workspace snippets should have precedence. There is this other issue, here in the VS Code repo #8102 .... however still leaves with the fact that I have to control for a certain extension to be installed in VS Code. As of now that is not possible with Plaster.

    All ideas are welcome. Thank you.

  11. Fred-Vatin commented on Aug 4, 2017

    @Fred-Vatin

    Currently, in last insider, there is no way AFAIK to have a common snippets file for CSS, LESS, SASS, etc. It is bulky. 😓

  12. 21 remaining items

  13. jrieken commented on Jan 5, 2018

    @jrieken
    Contributor

    Some more tweaks to the configure/creation picker. Now it groups things by existing snippets and allows to create new snippets (globally or per language)

    screen shot 2018-01-05 at 17 28 10

  14. pmolaro commented on Jan 8, 2018

    @pmolaro

    +1 for this

    I currently dev CFML and would love to be able to use HTML, CSS, CFML snippets all in the same .cfm file. I'd be good with the global.json solution proposed.

  15. nikpushkarski commented on Jan 31, 2018

    @nikpushkarski

    Thanks a lot for adding a new feature, but the global snippets still don't work inside both multiline and single line comments.

    /*
    don't work
    */

    // don't work too

  16. grigoryvp commented on Jan 31, 2018

    @grigoryvp

    +1 for the comment issue. While programming, I need snippets mostly to comment same stuff consistently. And the feature is not working for comments for no reason :(

  17. locked and limited conversation to collaborators on Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requeston-testplanrelease-notessnippets

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions