vscode snippet ๋ง๋ค๊ธฐ#
vscode๋ฅผ ์ฌ์ฉํ๋ค๋ณด๋ฉด snippet์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๊ณ market์์๋ installํด์ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ ์ต์ํด์ง์ง๋ง, ๊ฒฐ๊ตญ ๋๋ง์ ์์ฐ์ฑ์ ๋์ด๊ธฐ ์ํด์๋ ๋ณธ์ธ๋ง์ snippet์ ๋ง๋๋ ๊ฒ์ ์์์ผํ๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก๋ built in snippet
์ด๋ผ๋ ๋ด์ฅ ์ฝ๋ ์กฐ๊ฐ์ด ์กด์ฌํ๋ค. markdonwn์ด๋ ์ฝ๋ฉ์ ํ๋ค๋ณด๋ฉด ์ค๋ฆฌ์ฌ์ฉ ์์์ ์ถ์ฒํด ์ฃผ๋ ๊ฒ์ด ์ด๋ฌํ ๊ฒ๋ค์ด๋ค. ์ด๊ฒ๋ค์ ๋ถ๋ฌ์ ์ฌ์ฉํ๋ ค๋ฉด ctrl,cmd + space
๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
๋๋ง์ snippet#
์ฌ์ฉ์ ์ฝ๋ ์กฐ๊ฐ. ์ฆ ๋๋ง์ snippet์ ๋ง๋๋ ๊ฒ์ ๋ํด์ ์์๋ณด์. ์ฌ์ฉ์ ์ฝ๋์กฐ๊ฐ์ ~.json
ํ์ผ๋ก ์์ฑ๋๊ณ ๊ด๋ฆฌ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก text ํํ์ ๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ณ ์ด๋ฅผ ๋ถ๋ฌ์ค๋ ํ์์ผ๋ก json๋งํ๊ฒ ์๊ธฐ ๋๋ฌธ์ธ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค. ๊ทธ๋ฆฌ๊ณ vscode๋ ๊ธฐ๋ณธ์ ์ผ๋ก settings.json
์ผ๋ก ์ค์ ๋ ๊ด๋ฆฌํ๋ ๊ฒ์ ๋ณด๋ฉด json์ ๋ํด์ ์์๋์ผ๋ฉด ๋์ ๊ฒ์ด ์๋ค.
F1
\(\rightarrow\) Snippets:Configure User Snippets
\(\rightarrow\) new global snippet๋ก ๋ค์ด๊ฐ์ค๋ค. ๋ง์ฝ markdown์ด๋ ํน์ ์ธ์ด์ ํนํ๋ snippet์ด ํ์ํ๋ฉด ๊ทธ๊ฑธ ๋ง๋ค์ด ์ฃผ๋ฉด ๋๋ค.
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. 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": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
}
์ด๋ฐ ์์ผ๋ก ๊ธฐ๋ณธ์ ์ธ snippet์ด ๋์จ๋ค. ์ฝ์ด๋ณด๋ฉด ๊ท์ ํด์ผํ ๊ฒ์ด ์ด 5๊ฐ์ง ์ ๋๊ฐ ์๋ค.
name : ํด๋น snippet์ ์ด๋ฆ, suggestion์ ํ์
scope : markdown, js, java ๋ฑ ์ธ์ด
prefix :
ctrl,cmd + space
๋ฅผ ์ฌ์ฉ์ ์ด๋ค ๋จ์ถ์ด๋ก ์ฐพ์์งbody : ๋ด์ฉ
description : ํด๋น snippet์ ๋ํ ์ค๋ช
์์ ๊ฐ์ ๊ฒ๋ค์ ์ ๋ ฅํ๋ฉด ๋๋ค. ๋ค๋ฅธ ๋ถ๋ถ์ ์ด๋ ค์ธ ๊ฒ์ด ์๋๋ฐ body๋ถ๋ถ ์ ๋ ฅ์ ์์ด์ ๋ช ๊ฐ์ง ์์์ผ ํ ๊ฒ์ด ์๋ค.
body ์ ๋ ฅ syntax#
"basic snippet" : {
"scope" : "\"${0:language}\"",
"prefix" : ["snippet"],
"body" : ["\"${1:title}\" : {",
"\t\"prefix\" : [\"$2\"],",
"\t\"body\" : [\"$3\"],",
"\t\"description\" : \"$4\"",
"}"
],
"description" : "basic snippet"
},
json์์์ ๋ ํธํ๊ฒ ์ฐ๊ธฐ ์ํด์ ํด๋น snippet์์์ ์ฌ์ฉํ snippet์ ๋ง๋ค์ด ๋ณด์๋ค. ์ด๋ฅผ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด ๋ฌด์กฐ๊ฑด ์๋ฐ์ดํ๋ฅผ ์ฌ์ฉํด์ค์ผํ๋ค. ๊ทธ๊ฒ์ ์ํด์ ์ ๋ถ "\
์ด๋ฐ์์ผ๋ก ์ฌ์ฉํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ค๋ฐ๊ฟ์ ํ๋ ค๋ฉด "",
์ ๊ฐ์ ์์ผ๋ก ํด์ฃผ๊ณ tab์ด ํ์ํ ๊ฒฝ์ฐ์๋ \t
๋ก ์ฌ์ฉํด์ค๋ค.
๊ทธ๋ฆฌ๊ณ placeholder๊ฐ ์กด์ฌํ๋๋ฐ $~~
์ด๋ฐ์์ผ๋ก ํ๊ธฐ๋ ๊ฒ์ด๋ค.
$1
๋ ๋น์นธ์ผ๋ก ๋ณด์ด์ง๋ง${2:something}
์ผ๋ก ๋ ๊ฒ์ something์ด ๊ธฐ๋ณธ์ ์ผ๋ก ํ๊ธฐ๋๋ค.tabํค๋ฅผ ์ฌ์ฉํด์ 1,2,3โฆ ์์ผ๋ก ์ด๋ํ๋ฉด์ ์์ ์ด ๊ฐ๋ฅํ๊ณ
$0
์ ๋งจ ๋ง์ง๋ง ์์๋ฅผ ๊ท์ ํ๋ค. 0์์ ํ ๋ฒ๋ tabํค๋ฅผ ๋๋ฅด๋ฉด ํด๋น snippet ์์ ์ ํ์ถํ๋ค.``