What is a snippet in programming?

A text editor is one of the essential tools for programming.

When searching for recommended plugins and shortcuts in a text editor to make it easier to code, I often see the unfamiliar word "snippet".

This time, I, a programming beginner, investigated and summarized this "snippet".

Since it was investigated by beginners to the last, it may be a misunderstanding from the viewpoint of intermediate level and above, but I would be grateful if anyone who noticed it could point out.

Conclusion: Programming version of dictionary registration function

If you use a PC frequently, you have used the word dictionary registration function, haven't you?

If you register in advance so that when you type "A", you will get "Thank you."

If you type "A" and press the tab key, you can say "Thank you."

The snippet is a programming version of this dictionary registration feature.

A snippet means "fragment" and is said to refer to a part of source code or text in programming.

The following is a registered snippet used in the template engine "html.erb" used in Ruby on Rails, which is a Ruby framework.

erb.json


{
	"embedded Ruby": {
		"prefix": "erb",
		"body": [
				"<% $1 %>"
		]
	}
}
Words in the code meaning
embedded Ruby Snippet title
prefix Abbreviation
body Code that is converted when you enter the abbreviation and press the tab key

If you register like this, you can reduce unnecessary key input, reduce mistakes, and shorten the coding time, so I would like to actively increase snippets!

Bonus: How to register a snippet in Visual Studio Code

I will tell you how to register the above html.erb snippet with the text editor "Visual Studio Code" that I am currently using.

By the way, the PC environment is Mac.

  1. Open Visual Studio Code and click "Code"-> "Preferences"-> "User Snippets" in the upper left. スクリーンショット 2020-11-14 16.41.30.png

  2. Click "erb". スクリーンショット 2020-11-14 17.26.04.png

This is how erb.json opens. スクリーンショット 2020-11-14 17.26.26.png If you register the snippet as described above, you can easily enter long codes by simply entering the abbreviation.

Reference material

[Register a code snippet in VS Code and code efficiently! ](Https://haniwaman.com/vscode-snipet/#:~:text=VSCode%E3%81%A7%E3%81%AF%E5%90%84%E6%8B%A1%E5%BC% B5% E5% AD% 90,% E3% 81% 84% E3% 81% 8F% E3% 81% A4% E3% 81% 8B% E3% 81% 82% E3% 82% 8B% E3% 81% AF % E3% 81% 9A% E3% 81% A7% E3% 81% 99% E3% 80% 82)

Recommended Posts

What is a snippet in programming?
What is programming?
What is a class in Java language (3 /?)
[For programming beginners] What is a method?
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
What is a constructor?
What is a stream
What is a Servlet?
What is object-oriented programming? ~ Beginners ~
What is a boolean type?
What is a Ruby module?
What is a floating point?
What is a meaningful comment?
What is a jar file?
What is a Java collection?
What is a lambda expression?
What revolution happen in programming
What is a fa⁉ enum?
What is a column Boolean type?
What is a reference type variable?
What is @Autowired in Spring boot?
What is a lambda expression (Java)
[Swift] What is "inheriting a class"?
What is a Ruby 2D array?
What is a terminal? -Absolute path & relative path-
What is a Spring Boot .original file?
What is Swift? Findings obtained in 3 weeks
[Technical memo] What is "include" in Ruby?
What is the main method in Java?
[Rails] What is a dot (.) Or a colon (:)?
What is gem'foge', require: false in Gemfile?
What is a request scope? Image commentary
What is Cubby
What is Docker?
What is null? ]
What is Keycloak
What is maven?
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
Let's think about what declarative programming is in Java and Elm (Part 1)
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Pullback doing in The Composable Architecture
Introduction to Recursive Functions: What is a Recursive Function?
Make a snippet for Thymeleaf in VS Code
Androd: What to do about "The Realm is already in a write transaction in"