How to Create a Snippet in Visual Studio Code

How to Create a Snippet in Visual Studio Code

Tania Rascia  /  Leave a response

Here’s how you make a custom, global snippet in VSCode.

Press COMMAND + SHIFT + P to open the command palette.

Find “Preferences: Configure User Snippets”.

Click “New Global snippets file”. This will open up a file with a .code-snippets extension in ~/Library/Application Support/Code/User/snippets/filename.code-snippets.

I made one that will allow me to type perr + TAB to print forced PHP errors.

PHPErrors.code-snippets
{
	"Show PHP Errors": {
		"scope": "php",
		"prefix": "perr",
		"body": [
			"ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);"
		],
		"description": "Show PHP Errors"
	}
}

And that’s all.

Quality and morality on the web

Hi, my name is Tania Rascia. I've turned down every advertiser, sponsored post, and affiliate who has come to me. I give away all my knowledge for free to 300,000+ monthly readers and helped thousands of people learn and successfully transition into a design/development career.

You know what I stand for, and you know my commitment to you - no bullshit, no sponsored posts, no pop ups, no blocked content, ads, schemes, tactics, or gimmicks. Just free, quality content. If you enjoy my content, please consider supporting what I do!

Write a response

Your email address will not be published.

All code will be displayed literally.