Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

vscode snippets

Visual Studio Code User-Snippets Variables

With $name or ${name:default}, you can insert the value of a variable. 
When a variable isnt set, its default or the empty string is inserted. 
When a variable is unknown (that is, its name isnt defined) 
the name of the variable is inserted and it is transformed into a placeholder.

The following variables can be used:

    TM_SELECTED_TEXT The currently selected text or the empty string
    TM_CURRENT_LINE The contents of the current line
    TM_CURRENT_WORD The contents of the word under cursor or the empty string
    TM_LINE_INDEX The zero-index based line number
    TM_LINE_NUMBER The one-index based line number
    TM_FILENAME The filename of the current document
    TM_FILENAME_BASE The filename of the current document without its extensions
    TM_DIRECTORY The directory of the current document
    TM_FILEPATH The full file path of the current document
    RELATIVE_FILEPATH The relative (to the opened workspace or folder) file path of the current document
    CLIPBOARD The contents of your clipboard
    WORKSPACE_NAME The name of the opened workspace or folder
    WORKSPACE_FOLDER The path of the opened workspace or folder
    CURSOR_INDEX The zero-index based cursor number
    CURSOR_NUMBER The one-index based cursor number

For inserting the current date and time:

    CURRENT_YEAR The current year
    CURRENT_YEAR_SHORT The current year's last two digits
    CURRENT_MONTH The month as two digits (example '02')
    CURRENT_MONTH_NAME The full name of the month (example 'July')
    CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
    CURRENT_DATE The day of the month as two digits (example '08')
    CURRENT_DAY_NAME The name of day (example 'Monday')
    CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
    CURRENT_HOUR The current hour in 24-hour clock format
    CURRENT_MINUTE The current minute as two digits
    CURRENT_SECOND The current second as two digits
    CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch

For inserting random values:

    RANDOM 6 random Base-10 digits
    RANDOM_HEX 6 random Base-16 digits
    UUID A Version 4 UUID

For inserting line or block comments, honoring the current language:

    BLOCK_COMMENT_START Example output: in PHP /* or in HTML <!--
    BLOCK_COMMENT_END Example output: in PHP */ or in HTML -->
    LINE_COMMENT Example output: in PHP //
Comment

how to make snippets vscode

Hit > shift + command + p and type snippets
Select Preferences: Open User Snippets
Choose the language type for which you want to add the custom snippet
vscode has comments to explain on how to add a snippet, as described on :> vsdoc
Lets say, we want to open custom snippets for the language GO. Then we can do:

Hit > command + p
Type: go.json + enter And you land on the custom snippet page
Snippets are defined in a JSON format and stored in a per user (languageId).json file. For example, Markdown snippets go in a markdown.json file.

Update new tools:
Snippet generator site: https://snippet-generator.app/
Comment

create custom snippet vscode

/*To create or edit your own snippets, select User Snippets 
under File > Preferences > User Snippets (Code > Preferences on macOS), 
and then select the language for which the snippets should appear*/

// Snippets are written in JSON Example:
{
	"Your Snippet Name": {
      "prefix": "ysn",
      "body": [
          "//Here you type all the code that should appear",
          "//Separating each line",
          "//Remember to add tabs with 	"
      ]
    }
}
Comment

vscode snippets customize

Visual Studio Code, customize / make your own code snippets
For tutorial: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets
Premade snippets for Python: https://github.com/microsoft/vscode-python/blob/2020.12.424452561/snippets/python.json
Comment

vs code snippets

// in file 'Code/User/snippets/javascript.json' for only JS files
{
  "For Loop": {
    "prefix": ["for", "for-const"],
    "body": ["for (const ${2:element} of ${1:array}) {", "	$0", "}"],
    "description": "A for loop."
  }
}

// in file 'Code/User/snippets/fileName.code-snippets' for Global Snippets
{
  "For Loop": {
    "scope": "javascript,typescript,php,html",
    "prefix": ["for", "for-const"],
    "body": ["for (const ${2:element} of ${1:array}) {", "	$0", "}"],
    "description": "A for loop."
  }
}
Comment

create custom snippets visual studio code

npm install -g yo generator-code

yo code

fill your detils
Comment

vscode snippet custom

{
	"Include General Namespace": {
		"prefix": "Namesp",
		"body": [
			"using System;",
			"using System.Collections.Generic;",
			"using System.Linq;",
			"using System.Text;"
		],
		"description": "For Including General Namespace"
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity inspector sliders 
Csharp :: polymorphism in c# 
Csharp :: is it possible to be palindrome 
Csharp :: integer to boolean conversion in unity C# 
Csharp :: c# convert string to datetime 
Csharp :: unity reload script assemblies 
Csharp :: unity overlapspherenonalloc 
Csharp :: unity c# request store review 
Csharp :: protected override void OnExiting(Object sender, EventArgs args) { base.OnExiting(sender, args); Environment.Exit(Environment.ExitCode); } 
Csharp :: c# write line variable 
Csharp :: unity3d sort list 
Csharp :: c# download file from url 
Csharp :: how to make a enemy in unity 
Csharp :: ik nothing is happening unity 
Csharp :: C# a program to reverse each word in the given string. 
Csharp :: nethereum check gas price 
Html :: stylesheet einbinden html5 
Html :: html tab icon 
Html :: leading spaces html 
Html :: http://127.0.0.1:5500/favicon.ico 
Html :: meta no cache 
Html :: notyf 
Html :: centre text bootstrap 
Html :: difference between name and value in html 
Html :: html inbed youtube 
Html :: flex direction column bootstrap 4 
Html :: html skype chat link 
Html :: disable autoplay in html iframe 
Html :: target blank 
Html :: css border table none 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =