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
4
votes
3 answers

Is there a way to insert N times the same characters

I can't find if vscode has a such failure. Is there a way to construct a string with N characters? I explain myselft: I need to wrote an empty string like this: foobar = "1111111111111111"; There is 16 times characters '1'. Is there a way, like in…
beware
  • 51
  • 1
  • 4
4
votes
1 answer

vscode Nest snippet choices and add tab stops to choices

I want to do something like that in my snippets for visual studio code: "V.G.${1|BLOCK_NR,MASS_MM,MASS_360,I,J,K,R,FEEDRATE,FEEDRATE_SCALE,MERR[${2}]|}" So after choose the option MERR[] I will see the cursor inside the brackets. and how i have to…
user8184393
4
votes
1 answer

Keep $ for Powershell variable in VS code snippet

I’m able to save my code snippets with tabbed spacing in VS code for Powershell, but it keeps ignoring my variables by not displaying the $ for my variables when I call the snippet. It will just paste in the name and omit the $. How do you get VS…
dcvl
  • 485
  • 1
  • 7
  • 21
4
votes
2 answers

Pad selected lines to cursor position in VSCode

In Visual Studio 2019, I can use Alt+Shift+(Arrow Keys) to multi-line edit the "virtual" whitespace then press any key to make all the lines padded with space to the selected column, I use this a lot to make initialization code easier to read.…
James Nguyen
  • 1,079
  • 1
  • 10
  • 20
4
votes
2 answers

vscode snippet - transform and replace filename

my filename is some-fancy-ui.component.html I want to use a vscode snippet to transform it to SOME_FANCY_UI So basically apply upcase to each character Replace all - with _ Remove .component.html Currently I…
Han Che
  • 8,239
  • 19
  • 70
  • 116
4
votes
3 answers

VSCode Advanced Snippet Transform

I'm trying to create a snippet that creates a class name based on the file path. If the file is named index.js, I'd like the class name to take the folder name. Otherwise, use the file name. I've got a transform (shown below) that is currently…
4
votes
1 answer

How to disable Enter button for code snippet in VSCode

Sometimes when I press the Enter button, VSCode will aggressively complete the code which I don't want. For example: When I type in the import numpy as np and press the enter, VSCode will change the np to numpy or when I type in the else and…
3
votes
1 answer

Why aren't choice snippets working properly in new files in VS Code 1.80.0?

For example, choice-type snippet suggestions are not showing up as I expect in version 1.20.0 of the redhat.java extension for VS Code. That includes snippet suggestions and other code suggestions. I observe this every time I create a new file. In…
starball
  • 20,030
  • 7
  • 43
  • 238
3
votes
1 answer

Adding Dollar Sign($) in a VScode Code snippet

I was writing my custom code snippets for verilog files in VScode; VSCode uses JSON files for it. I observed that $ before finish and dumpvars statements doesn't get printed when I use the snippet since it is a built-in keyword for including…
3
votes
2 answers

About adding a snippet for python in vs code

How to write a snippet for 'main' function in vs code? It's not allowing to put double "" in between the body. Here is what I have written: "Print to console": { "prefix": "mai", "body": [ "if __name__ == __main__:" …
Edeath
  • 31
  • 5
3
votes
1 answer

Replace backslash '\' with forward '/' slash in VS Code snippets with Regex

Background: I am adding a custom JavaScript snippet in VS Code to insert the file path of the current file. VS Code provides variables to get the file path but the file path contains backslashes in the path. And I want to get the path with '/'…
Mohit Yadav
  • 145
  • 1
  • 12
3
votes
2 answers

In VSCode snippets how do you use transform to lowercase just the first letter of a value?

I've just started getting into vsCode snippets. They seem really handy. Is there a way to ensure that what a user entered at a tabstop starts with a lowercase value. Here's my test case/ sandbox : "junk": { "prefix": "junk", "body": [ …
samantha
  • 171
  • 1
  • 1
  • 8
3
votes
2 answers

VSCode's User Snippets Not Working for Markdown and Latex Files

I have gotten user snippets in VSCode to work for C and C++, but for some reason VSCode is not providing snippet suggestions for .md and .tex files. Here is a minimal example of tex.json (that doesn't work): { "dummy": { "prefix":…
3
votes
1 answer

Putting curly braces on the same line in C when autocompleting snippets with VSCode Intellisense

I am a long time Atom user. I finally decided to switch over to VS Code but there is one thing that if I cannot solve I am going back to Atom. I am a hardware engineer so I primarily write C code. I am looking for a way to fix the IntelliSense…
3
votes
1 answer

Visual studio code snippet choices and variables

I am writing my own snippet to console.log { "Print to console": { "scope": "javascript,typescript", "prefix": "debug", "body": [ "console.log('${1|[Debug],[Server],[$TM_FILENAME]|}','${2:~Line: $TM_LINE_NUMBER ~…
alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
1 2
3
25 26