Base configuration VsCode snippets

To create a custom vscode code snippets it’s pretty straightforward

Navigate inside vscode

File -> Preferences -> User Snippets

Select the one based in the visibility

In this example “new global snippets file” (with ubuntu it’s saved into ~/.config/Code/User/snippets)

The following code defines two snippets:

  • when the dev type “cl” in scope “javascript or typescript” it’s print a console.log
  • when the dev type “bashscaff” in scope “shell script” it’s print a base bash scaffolding
{
	"console.log": {
		"scope": "javascript,typescript",
		"prefix": "cl",
		"body": [
			"console.${2|log,error,info,table,count,dir|}(`${1:text}`);"
		],
		"description": "Log output to console"
	},
	"bash.scaffolding": {
		"scope": "shellscript",
		"prefix": "bashscaff",
		"body": [			
			"#!/bin/bash",
			"if [ -z \"\\$1\" ]; then",
			"    echo \"Param is empty\"",
			"    exit",
			"fi",
			"if [ \"\\$1\" == \"value\" ]; then",
			"    echo \"Do custom stuff for param 1\"",
			"fi"
		],
		"description": "bash scaffolding"		
	}
}

Categories: Bash

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.