When developing rails, I often write "<% =%>" and "<%%>". It's quite annoying to hit each one. So let's use VScode's snippet feature to easily reduce the time it takes to type these annoying chords! Of course, other languages are OK!
You can make snippets freely, And how to write as follows In the first "", ** the brief content of the snippet ** After prefix, ** trigger to output snippet ** After the body, ** the content of the code you actually want to output ** After description, ** description of snippet ** Write!
ruby
{
// Place your snippets for erb 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:
"write <%=%> more easier": {
"prefix": "pa",
"body": [
"<%= $0 %>"
],
"description": "Log output to console"
}
}
You can also specify the cursor position by multiplying by $ 0. If you use the example above, the cursor will be placed between = and% in <% =%>. Similarly, you can insert a line break by multiplying by $ 1 or $ 2.
You can also create multiple snippets by writing:
ruby
{
// Place your snippets for erb 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:
"write <%=%> more easier": {
"prefix": "pa",
"body": [
"<%= $0 %>"
],
"description": "Log output to console"
},
"write <%%>": {
"prefix": "ni",
"body": [
"<%%>",
],
"description": "Log output to console"
}
}
Author: Kazuhito Nakayama Twitter Qiita
Recommended Posts