VS Codeμ μ€λν«(Snippet) κΈ°λ₯μ μ¬μ©νλ©΄ λ°λ³΅μ μΈ μ½λ μμ± μκ°μ μ μ½νκ³ , μ½λμ μΌκ΄μ±μ μ μ§ν μ μμ΅λλ€. μλλ μ€λν« μμ± λ°©λ²κ³Ό νμ©λ²μ λν μ 리μ λλ€.
File > Preferences > User Snippets
μμ μμ±..vscode/
ν΄λμ μ μ₯λ μ€λν« νμΌ.μ€λν«μ JSON νμμΌλ‘ μμ±λ©λλ€.
{
"μ€λν« μ΄λ¦": {
"prefix": "trigger", // ν€μλ
"body": [ // μ½λ λ΄μ©
"μ½λ λΌμΈ 1",
"μ½λ λΌμΈ 2"
],
"description": "μ€λͺ
" // (μ ν) μ€λν« μ€λͺ
}
}
console.log
λ₯Ό λΉ λ₯΄κ² μ
λ ₯νλ μ€λν«:
{
"Console Log": {
"prefix": "clg",
"body": ["console.log('$1');"],
"description": "Insert a console.log statement"
}
}
clg
μ
λ ₯ ν Tab
ν€.console.log('');
λ³μ μ¬μ© ($)
$1
, $2
λ±μΌλ‘ 컀μμ μμΉλ₯Ό μ§μ ν μ μμ΅λλ€.${N:default}
ννλ‘ κΈ°λ³Έκ°μ μ§μ ν μ μμ΅λλ€.{
"Function Template": {
"prefix": "func",
"body": [
"function ${1:functionName}(${2:args}) {",
" $0",
"}"
],
"description": "Insert a function template"
}
}
func
μ
λ ₯ ν Tab.
function functionName(args) {
}
λ°λ³΅ ν μ€νΈ μ ν κ°λ₯:
{
"For Loop": {
"prefix": "forloop",
"body": [
"for (let ${1:i} = 0; ${1} < ${2:10}; ${1}++) {",
" console.log(${1});",
"}"
],
"description": "Insert a for loop"
}
}
Trigger: forloop μ
λ ₯ ν Tab.
μμ± κ²°κ³Ό
for (let i = 0; i < 10; i++) {
console.log(i);
}
λ¨μΆν€: Ctrl+Shift+P β Preferences: Configure User Snippets μ ν.
μ¬μ©ν μΈμ΄ λλ New Global Snippets File μ ν.
μμ±λ JSON νμΌμ μ€λν« μΆκ°.
>Windows: %APPDATA%\Code\User\snippets
>macOS: ~/Library/Application Support/Code/User/snippets
Linux: ~/.config/Code/User/snippets
{
"React Functional Component": {
"prefix": "rfc",
"body": [
"import React from 'react';",
"",
"const ${1:ComponentName} = (${2:props}) => {",
" return (",
" <div>",
" ${3:/* content */}",
" </div>",
" );",
"};",
"",
"export default ${1:ComponentName};"
],
"description": "Create a React functional component"
}
}
{
"HTML Boilerplate": {
"prefix": "html5",
"body": [
"<!DOCTYPE html>",
"<html lang=\"${1:en}\">",
"<head>",
" <meta charset=\"UTF-8\">",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
" <title>${2:Document}</title>",
"</head>",
"<body>",
" $0",
"</body>",
"</html>"
],
"description": "Basic HTML5 boilerplate"
}
}
.vscode/snippets.json
μ μ μ₯.