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
0 answers

How to insert Last Modified Date & Time in VScode

I created the following C++ snippet in VS Code. /** * Author : Sakib62 * Created: Fri__01.Jul.2022__03:59:25 * File : 3.cpp **/ #include using namespace std; int main() { } I added Current time and…
2
votes
2 answers

Cannot join two regex into one to produce a code snippet to use in VSCode

I am struggling with regular expressions and how to use them in snippets in VSCode and I could really use some help (I am a beginner in that area). I have two regexp: the first one is here to remove the extension from a file path: (.*)\.[^.]+$ the…
2
votes
2 answers

PowerShell 5.1 What's the difference between inline function and all the other ones?

I'm using PowerShell 5.1 and I'm using inline functions just fine in my script. But I can't find anything online telling me why I wouldn't use inline functions. My main context is using Azure pipeline tasks to call my PowerShell scripts.
Rod
  • 14,529
  • 31
  • 118
  • 230
2
votes
2 answers

Cant figure out user snippets

I am trying to make another user snippet in VSCode to automate the document.querySelector but whenever I try to it gives me a weird error shown below. I have another snippet that works just fine but that was shown to me by an online class I am…
Bruck
  • 33
  • 5
2
votes
2 answers

Inserting n,...,n+k number in k lines in visual studio code

I want to insert [11,12,...,20] in 10 lines of vscode editor, somehow I want to simulate iota functionality of golang in vscode editor, for example let assume we had this lines in vscode editor: line1 xxxxx line2 xx line3 xxxxxxxx . . . line10…
S4eed3sm
  • 1,398
  • 5
  • 20
2
votes
2 answers

Replace and upper case in a snippet with vscode

I'd like to replace Context in myAppContext and upper case on tab pressing, so the end result should be MyApp. I would rather do it all at once. Here's where I started.: To remove 'Context' I can do ${1/Context//} and for uppercase:…
cyrus-d
  • 749
  • 1
  • 12
  • 29
2
votes
2 answers

Regex Statement in VSCode snippet for removing file extension

I'd like to create a VS-Code snippet for importing css into a react component. If I'm using the snippet in "MyComponent.tsx", then I'd like the snippet to import the associated css file for the component: import "./MyComponent.css"; The component…
ANimator120
  • 2,556
  • 1
  • 20
  • 52
2
votes
2 answers

vscode snippet - multiple regex transformation filepath+filename

after 1 week of searching and try&error I'm creating this question in the hope of someone willing to help me out on this one: My VsCode Snippet should transform the…
2
votes
1 answer

How to capitalise a letter in a custom snippet?

I am trying to create a snippet using vs code (javascript.json) to do the following code. const [click, setClick] = useState(false) I have created the following snippet which sort of works. "My Custom useState": { "prefix": "myus", …
Will
  • 1,001
  • 1
  • 6
  • 12
2
votes
2 answers

How to disable dot emmet intellisense for JS files in VS Code

I want to use emmet in a Javascript file that contains JSX code but I don't want IntelliSense to suggest an emmet whenever I use the dot (.) operator. For example, I don't want the .rap emmet suggestion to show up: I tried these…
Cvai
  • 23
  • 1
  • 6
2
votes
1 answer

Nested regex replacement in VS Code Snippet

I've made a mistake in making a lot of bold readings in restructured text (rst) files where I should've used a different heading style. I need to replace: **some heading** with: some heading ............ I'm wanting to do this with VS Code…
skelliam
  • 522
  • 3
  • 11
2
votes
1 answer

Is it possible to add a a variable within a placeholder transform in Visual Studio Code?

I am looking to write an visual studio code user snippet like this: "Surround With Div": { "prefix": "sdiv", "body": ["${1/(.*)/
${TM_SELECTED_TEXT}<\\/div>/}"], "description": "Surround With Div" } But it does not…
2
votes
1 answer

const case in vscode snippets

Hey i'm looking for a way to make a vscode snippet turn my variable name to const case: for example ${1:regular} ${1:/constCase/} if I write heyThisIsVariable in it, it will become: heyThisIsVariable HEY_THIS_IS_VARIABLE
Ivan Solobear
  • 399
  • 1
  • 3
  • 8
2
votes
1 answer

Is there a way in VS Code to see the source of an autocomplete snippet?

As a followup to this question, in my VS Code I have a bunch of autocomplete snippets I haven't been able to ascertain the source of. All the snippets in the image below give me indentation problems when autocompleting. autocompletes to Notice the…
Mate de Vita
  • 1,102
  • 12
  • 32
2
votes
1 answer

Perform math on VSCode snippet variables

My goal is to have VSCode insert a timestamp whenever I press Ctrl+Shift+I that looks like this: [15:03] Currently the following keybinding gets me almost there: { "key": "ctrl+shift+i", "command": "editor.action.insertSnippet", "when":…
Daniel
  • 678
  • 1
  • 5
  • 20