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

how to make user snippets work inside strings: vscode

I've made own user snippet code for javascript "inner backquote concat variable" : { "prefix": "$", "body": "\\${$1}", "description": "concat variable with backquote sting" } I want that snippet to work inside backquote string or single…
7
votes
1 answer

VS Code snippet with multiple transforms

I am trying to make a snippet that will take clipboard contents (the text of a heading in a markdown document) and transform it into a link to that section. For example, if my clipboard contains: Some Heading - 20191107 then I want the following to…
Robert Mark Bram
  • 8,104
  • 8
  • 52
  • 73
7
votes
2 answers

Add custom auto imports to vscode

if I type autorun inside the code, vscode suggests me to auto import it from mobx: I want to define some custom names for that for example if I type _ somewhere in the code, I want vscode to suggest me to import lodash or if type PropTypes I want…
7
votes
4 answers

How to remove the file extension using a snippet variable. List of snippet variables

I use vscode. I want to use costum snippets, but {TM_FILENAME} has an extension name. How can I delete the extension from {TM_FILENAME}? like this:` In file MyModule.js: Transform: ${TM_FILENAME/(\w+)\.js/\1/g} Output: MyModule
Chen Xiang
  • 73
  • 1
  • 4
6
votes
2 answers

Snippet regex: match arbitrary number of groups and transform to CamelCase

In a Visual Studio Code Snippet I'm writing I want to convert a snake case string to camel case. From the docs I know that the syntax is '${' var '/' regex '/' (format | text)+ '/' options '}' so I've come up with this…
Darya
  • 89
  • 1
  • 3
5
votes
6 answers

Visual Studio Code functional snippet React

Does anybody knows what's the shortcut for React functional components snippet in Visual Studio? I have the ES7 React/Redux/GraphQL/React-Native snippets extension enabled in the editor.
Sergey Kirillov
  • 351
  • 1
  • 3
  • 10
5
votes
2 answers

How can you capitalize this word in VIM snippet?

EDIT — This is not possible with coc-snippets. It's possible with Ultisnips. I've got the following vim snippet that I'm using (with coc-snippets) for React: snippet STATE_HOOK "useState hook" b const [${1:state}, set${1:`!v expand('%:t:r')`}] =…
Harrison Cramer
  • 3,792
  • 9
  • 33
  • 61
5
votes
2 answers

How do I make VSCode JavaScript import snippet use single quotes?

The VSCode setting "javascript.preferences.quoteStyle": "single" did not work for me and I'm still getting double quotes in my JavaScript snippets as shown in the picture: Is there a way I can make VSCode use single quotes without having to use any…
Kewal Shah
  • 1,131
  • 18
  • 29
5
votes
1 answer

Setting character $ to wrap text as parentheses in vscode

Suppose following code exists. sample text When user double click text, then press { or (, it just wraps the text while keeping it. sample {text} sample (text) But I don't know how to apply this rule to $ in VS Code Settings. What I expect…
lee
  • 185
  • 2
  • 8
5
votes
1 answer

Make a vscode snippet that can use a variable number of arguments

I am new to VSCode. Thinking about code snippets, I looked around for a way to kind of script inside the snippet. I mean to do more than just fill or transform a variable. For example... This is a simple snippet. I am going to type rci for the class…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
5
votes
2 answers

VSCode Code-Snippets transform: downcase and capitalize at the same time

I have this: ${1/([A-Z]*)(?:_)([A-Z]+)*/${1:/downcase}${2:/downcase}/g} How to make use downcase and capitalize on the same (2) group? ${1/([A-Z]*)(?:_)([A-Z]+)*/${1:/downcase}${2:/downcase/capitalize}/g} I want to tansform ZXC_ASD to zxcAsd.
4
votes
1 answer

VSCode — Commit custom snippets to repository

How do I share my custom snippets with my colleagues through a repository? For example, sharing a javascript.json file. I know it should go inside .vscode, but where exactly and with what exact config?
sandrina-p
  • 3,794
  • 8
  • 32
  • 60
4
votes
0 answers

Visual Studio snippet - How to convert first letter to lowercase

In Visual Studio, I would like to update the fullprop snipped to automatically convert the field name according to property name: (and so only enter "property name" & "type") public string MyTest { get => _myTest; set { if…
Belight
  • 205
  • 2
  • 14
4
votes
0 answers

Visual studio code snippets for Javascript inside .php files

I've got two debug snippets, one for PHP, one for Javascript. I use the same keyboard binding: { "key": "ctrl+D", "command": "editor.action.insertSnippet", "when": "editorTextFocus && editorLangId == 'php'", "args": { "langId": "php", …
4
votes
2 answers

Is it possible to have a snippet that considers the length of my input?

I would like to define a snippet for comments like //************ //* foo A1 * //************ where I enter foo A1 and it would create a line with (6+ len(${1}) asterisks etc. - is that doable and if so, how?
MBaas
  • 7,248
  • 6
  • 44
  • 61
1
2
3
25 26