Skip to main content

Snippets

Creating custom language-specific snippets. (CFML)

There are two parts for effectively using commonly used snippets in VC Code. The first part involves configuring snippets with the second part mapping the created snippets to keyboard shortcuts.

Defining custom snippets.

Select "User Snippets" under File => Preferences Visual Studio Docs (User Defined Snippets)

launch.json
{
// Place your snippets for cfml here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }

"CF_Query_Param": {
"prefix": "cfqp",
"body": "",
"description": "CF Query Param"
},
"CF_Abort": {
"prefix": "cfab",
"body": "",
"description": "CF Abort"
},
"CF_Dump": {
"prefix": "cfdu",
"body": "",
"description": "CF Dump"
},
"CF_Output": {
"prefix": "cfou",
"body": "$TM_SELECTED_TEXT$0",
"description": "CF Output"
},
"CF_fn": {
"prefix": "cffn",
"body": ["", " $TM_SELECTED_TEXT", " ", ""],
"description": "Function definition using tags"
}
}

Mapping keyboard shortcuts to snippets.

  1. Select "Keyboard Shortcuts" under File => Preferences
  2. Right-click the "open keyboard shortcuts file.json" icon. (top right)

Note: The keybindings are mapped to the name of the snippet.

keybindings.json
// Place your key bindings in this file to override the defaults
[
{
key: "ctrl+alt+o",
command: "editor.action.insertSnippet",
when: "editorTextFocus && !editorReadonly && editorLangId == 'cfml'",
args: {
name: "CF_Output",
},
},
{
key: "ctrl+alt+d",
command: "editor.action.insertSnippet",
when: "editorTextFocus && !editorReadonly && editorLangId == 'cfml'",
args: {
name: "CF_Dump",
},
},
{
key: "ctrl+alt+a",
command: "editor.action.insertSnippet",
when: "editorTextFocus && !editorReadonly && editorLangId == 'cfml'",
args: {
name: "CF_Abort",
},
},
];