Questions tagged [vscode-snippets]

For issues relating to the creation, use, and maintenance of code snippets in Visual Studio Code

Overview

A snippet is a small region of re-usable source code, machine code or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise "cluttered" function, or to minimize the use of repeated code that is common to other functions.

See also

384 questions
54
votes
7 answers

What's The Best Way To Write Multi-Line Code Snippets In VS-Code?

In Sublime Text, multi-line code snippets can be defined with white-spaces in a snippet file. But as far as I know, VS-Code needs a JSON entry. These require either: Hard-breaks into a list of double-quoted strings, or Soft-break a long string…
kakyo
  • 10,460
  • 14
  • 76
  • 140
42
votes
3 answers

Visual Studio Code : Sort functions by name?

Is it possible to sort functions by name in Visual Studio Code ? I mean, using a keyboard shortcut or even an extension. Precision: I'm spaeking about sorting the functions in the panel code editor.
39
votes
4 answers

VS Code: How to convert snippet placeholder to uppercase or lowercase?

In VS Code, the docs for creating user defined snippets mentions some Grammar which includes options for /upcase, /downcase, and /capitalize, but I can't figure out how to use it. I'm using the latest version of VS Code: Version 1.25.0 on Mac. It…
Beau Smith
  • 33,433
  • 13
  • 94
  • 101
36
votes
4 answers

Intellisense not working in code snippets - VS Code

I have installed the C# extension in VS Code. The problem I am having is, after using a code snippet prop, Intellisense no longer suggests variable types. This happens with other things like ctor as well, it will not autocomplete the class name, for…
23
votes
1 answer

visual studio code add corresponding import statements for snippets

I tried to create custom snippets for my extension in vscode. But to use those snippets I also need specific imports statements, I'm trying out to figure out how to add corresponding import statements while a snippet is selected from choices.? Does…
zedge
  • 239
  • 2
  • 3
21
votes
1 answer

VS Code: How to convert snippet placeholder from camelCase to SCREAMING_SNAKE_CASE?

I'd like to create a VS Code snippet for creating redux reducers. I would like to have a snippet with placeholder that expects camelCase and then transform a matching placeholder to SCREAMING_SNAKE_CASE. Here's my attempted snippet, which is not…
Beau Smith
  • 33,433
  • 13
  • 94
  • 101
19
votes
2 answers

VSCode user snippet to generate useState for React?

I'm trying to create a VS code user snippet for useState() Currently I have "use state": { "prefix": "us", "body": [ "const [$1, set${1/(.*)/${1:/upcase}/}] = useState($2);", "$3" ], "description": "creates use state" …
18
votes
1 answer

Recording a 'macro'? or a series of actions in Visual Studio Code?

I would need something like this. Once I create a folder within a project. A React Project for example. I could select that folder and run some kind of macro or series of actions that would do this. Provided that the name of the folder is Component…
13
votes
1 answer

Capitalize first letter of VSCode snippet

I want to create VSCode snippet to quickly use React's useState. E.g. for a state open const [open, setOpen] = useState() I'm currently using "const [ ${1}, set$1 ] = useState()" But this gives me const [open, setopen] = useState(). Note the lack…
Henry
  • 165
  • 1
  • 6
13
votes
3 answers

When creating a VSCode snippet, how can I transform a variable to title-case (like TitleCase)?

https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholdertransform My aim is to automatically set the class name within the context of the snippet being inserted. VSCode does not natively support class or method names, but it does…
13
votes
3 answers

Snippets with indentation in Visual Studio Code

I'm trying to create a snippet in Visual Studio Code. This works, but the indentation is missing: My snippet : "HTML structure": { "prefix": "html", "body": [ "", "", "", …
Jeremy
  • 1,756
  • 3
  • 21
  • 45
13
votes
4 answers

Using TM_SELECTED_TEXT in my custom snippets

With the November 2016 (version 1.8) release of VSCode Snippet Variables are now supported, specifically TM_SELECTED_TEXT. This makes me happy as I have used these heavily in both Sublime Text and TextMate. I can't figure out how to get it to work…
12
votes
2 answers

Dynamic snippet evaluation in VSCode

Is it possible for a snippet to insert a dynamically computed completion or snippet in Visual Studio Code? I would like a snippet for inserting date and time strings of various formats. For example if you type date, the current date in ISO format…
Chris Scott
  • 1,721
  • 14
  • 27
11
votes
2 answers

VSCode nested snippets (or include a snippet inside another snippet)

I'm wondering if I can refer to another snippet within a snippet in VSCode user defined snippet. Say I have "Test1": { "prefix": "snippet_test1", "body": "something" } and is there a way to insert snippet_test1 in…
Jin Yan
  • 151
  • 1
  • 5
10
votes
2 answers

VS Code No Longer Shows Default Code Snippet for Python

For some unknown reasons, my VS code no longer shows the default code snippets for Python. Below is what I see when I type for in the editor (to write the for loop) I'm expecting to see something like below: All snippets seem to be missing. Not…
1
2 3
25 26