1

As an example I would like to add "lorem ipsum" as a snippet, so I can quickly insert it where I want. I don't want it do be tied to a specific language, as I might use it in multiple places like HTML, Jade, even JS/TS.

Is there like a global.json for snippets, or any other way to do this?

iuliu.net
  • 6,666
  • 6
  • 46
  • 69
  • Functionality like "lorem ipsum" probably wouldn't be implemented as a snippet, but as an extension. Pressing TAB after typing `lorem` in VS Code does not always result in exactly the same text. – stakx - no longer contributing Nov 12 '16 at 10:33
  • I made as a rule for myself to prefix my snippets with "_", so I can know for sure that if I hit tab it's a snippet. :) And why do you think that it would need to be an extension? – iuliu.net Nov 12 '16 at 10:44
  • I just explained that: "expanding" `lorem` with TAB does not always result in the same text. So there must be something dynamic going on. As far as I can see, snippets only allow placeholders to be subsequently filled in by the user, but no execution of scripts etc. See e.g. http://stackoverflow.com/questions/39413783/dynamic-snippet-evaluation-in-vscode. (AFAIK the "lorem" thingy built into VS Code relies on [Emmet](http://emmet.io), which btw. also supports more complex expansion rules, e.g. `li*5>p.item*10>lorem` which will generate HTML once you've typed it and pressed TAB twice.) – stakx - no longer contributing Nov 12 '16 at 12:04
  • Ohhhh. So it actually exists inside VScode. Didn't know that. Might aswell post that as an answer, thanks. – iuliu.net Nov 12 '16 at 18:52
  • Possible duplicate of [How to add common language snippets in Visual Studio Code?](https://stackoverflow.com/questions/40935738/how-to-add-common-language-snippets-in-visual-studio-code) – Alex Jan 05 '18 at 22:37

2 Answers2

1

Global snippets were added in v1.10 Feb., 2018 see global snippets

VS Code now supports global snippets meaning snippets that aren't scoped to a single language but can target any kind of files. Using the Preferences: Configure User Snippets command, select the New Global Snippets file... option which will open a .code-snippets file for new snippets. Use the scope attribute to list the languages that are targeted by a snippet. For instance, the snippet below can add a copyright header for JavaScript and TypeScript files:

From the documentation:

"JS & TS Stub": {
  "scope": "javascript,typescript",
  "prefix": "stub",
  "body": [
    "/*--------------------------------------------------------------",
    " *  Copyright (c) Your Corporation. All rights reserved.",
    " *  Licensed under the MIT License.",
    " *-------------------------------------------------------------*/",
    "",
    "'use strict';",
    "",
    "$0"
  ],
  "description": "Insert Copyright Statement"
}
Mark
  • 143,421
  • 24
  • 428
  • 436
0

VS Code doesn't have a global scope afaik. However, I made an npm package called Snipster that changes the way you write snippets and allows you to publish a global scope to all languages by naming the snippet with a .all extension. It also works with Atom and Sublime, not just VS Code.

For example: lorem.all

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ultrices nulla eget lectus pharetra dignissim. Curabitur molestie odio sed odio porttitor efficitur. Nulla vulputate porta quam, nec aliquam nisi gravida ac. Donec quis risus sed odio accumsan commodo id vel enim. Vivamus quam mauris, rutrum at vulputate quis, hendrerit eu velit.
jhanstra
  • 11
  • 2