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.
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!
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.
Open Visual Studio Code and click "Code"-> "Preferences"-> "User Snippets" in the upper left.
Click "erb".
This is how erb.json opens. If you register the snippet as described above, you can easily enter long codes by simply entering the abbreviation.
[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