Let's take advantage of VScode's snippet function ~ I don't want to hit <% =%> anymore ~

Overview

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!

How to introduce

Click the gear mark at the bottom left of VScode

スクリーンショット 2021-01-16 13.39.34.png

Open Command palette

スクリーンショット 2021-01-16 13.36.46.png

Type snippets and select the language extension of the code you want to omit

スクリーンショット 2021-01-16 13.37.32.png

スクリーンショット 2021-01-16 13.38.04.png

Write a snippet

スクリーンショット 2021-01-16 13.38.35.png

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"
	}
}

the end

Author: Kazuhito Nakayama Twitter Qiita

Recommended Posts

Let's take advantage of VScode's snippet function ~ I don't want to hit <% =%> anymore ~
I want to output the day of the week
I want to var_dump the contents of the intent
I want to call a method of another class
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to define a function in Rails Console
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to add a delete function to the comment function
[Rails] I don't want to get lost anymore. Create new models, tables, controllers and views.
I want to implement a product information editing function ~ part1 ~
I want to expand the clickable part of the link_to method
I want to make a specific model of ActiveRecord ReadOnly
I want to change the log output settings of UtilLoggingJdbcLogger
[Swift] I tried to implement the function of the vending machine
I want to make a function with kotlin and java!
I want to narrow down the display of docker ps
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController