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
2
votes
2 answers

VSCode snippets refresh required after change?

After changeing an user snippet I,d like to use it. Is there any other way to update the snippets besides restarting VSCode?
theq
  • 111
  • 2
  • 10
2
votes
1 answer

Snippet to create Snippet in SSMS

Problem: Usually, if you want to save your code as a snippet, you have to open some xml template, investigate tags etc. Reference Is it possible to simplify this process as much as possible: i.e. create a SurroundsWith snippet that will wrap…
Denis
  • 625
  • 1
  • 8
  • 28
2
votes
1 answer

vscode if/else conditions in user defined snippet

Looking at the vscode documentation for user defined snippets, it would appear that using the regex transform, you can do if/else conditions. However, I can't seem to find any examples of this and I'm struggling to understand the correct syntax…
NSjonas
  • 10,693
  • 9
  • 66
  • 92
2
votes
1 answer

Is there a way to trim a TM_FILENAME beyond using TM_FILENAME_BASE?

I am trying to create a snippet for a redux container file that takes an import of some react file of the same base name. TM_FILENAME_BASE works great for removing the .js from the file name but in this case, my component file's extension is…
kbDS
  • 35
  • 2
2
votes
3 answers

How to create a shortcut to print a variable (vscode)

How can I create a custom shortcut for generating code that will print a selected variable in vscode? [1] arr = [1,2,3,4] # I press double left mouse button on 'arr' [2] print(arr) # Then I press (Ctrl+p for example) …
2
votes
1 answer

Is there a way to use regex expression in vscode snippet prefix?

I read the document and it seems that regex expression is only used in snippet body.
kakakali
  • 159
  • 1
  • 11
2
votes
1 answer

VSCode snippet: add variable number of objects to a class constructor

I am trying to create a simple snippet that allows me to create JS Constructors. So far, what I have is "class constructor": { "prefix": "class", "body": [ "class ${1:ClassName} {", "\t\tconstructor({${2:thisName}:…
securisec
  • 3,435
  • 6
  • 36
  • 63
2
votes
0 answers

VS Code Snippets

I'm trying to write my own snippets in vscode. I was wondering, if it is possible to add variables such as Rigidbody and Animator and reference them with GetComponent() method all inside Start() function separately at any time during development…
2
votes
3 answers

How to do IntelliSense for snippets when some text is selected in VSCode?

I wrote my first snippet which would wrap the selected text in if() { selected text } block. "if block - snippet": { "prefix": "if block - snippet", "body": [ "if( $1 ) {", "$TM_SELECTED_TEXT", …
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
2
votes
1 answer

Transform and regex in Code Snippets in VSCode - Docs

I need list of transormations, like downcase, upcase, capitalize. Where is the list of such? Good documentation.
2
votes
1 answer

How to define default values for snippet placeholders?

When creating snippets I would like to know if it is possible to define a default value for a placeholder if no value is assigned. For example, having this php snippet: { "get_list": { "prefix": "get_list", "body": "$${1:beanList}…
Mario
  • 4,784
  • 3
  • 34
  • 50
2
votes
0 answers

XML to select a word (within code snippet)

I have this snippet <_locDefinition xmlns="urn:locstudio"> <_locDefault _loc="locNone" /> <_locTag…
whytheq
  • 34,466
  • 65
  • 172
  • 267
1
vote
1 answer

how can i make a code snippet in vscode / Ultisnips(vim) that can have variable number of arguments (tab triggers) like this:

if i type input5, then it produces code like: cin >> $1 >> $2 >> $3 >> $4 >> $5;$0 and if i type input2, then it produces code like: cin >> $1 >> $2;$0 Another example: if i type arrinputmn (where m and n is the size of mxn matrix), then it produces…
1
vote
3 answers

Visual Studio Code snippet: convert 'PascalCase' to lowercase with spaces

I'm trying to write a Visual Studio Code snippet that converts Pascal case to lowercase with spaces. I'm almost there: ${1/([A-Z]*)([A-Z][a-z]+)/$1 ${2:/downcase} /g} Group 1 matches acronyms and group 2 matches capitalized words. So if the…
JakesMD
  • 1,646
  • 2
  • 15
  • 35
1
vote
3 answers

VS Code snippet to capitalize each word in filename

I'm trying to write a code snippet to capitalize each word in the filename base where the words are separated by dashes. While I know the words in the filename base will be separated by dashes, I don't know how may words to expect in the filename…
the_meter413
  • 231
  • 3
  • 19