CS/Tip

vscode snippet ๋งŒ๋“ค๊ธฐ

๐Ÿธminzzi 2024. 7. 22. 20:59

console.log๋กœ ๋กœ๊ทธ๋ฅผ ์ฐ๋Š”๋‹ค๊ฑฐ๋‚˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค๋•Œ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค ๋•Œ์˜ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค๋•Œ๋ผ๋˜์ง€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์•ผํ•˜๋Š” ๋ผˆ๋Œ€๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ถ€๋ถ„์„ ์ด์ œ๋Š” ์™„์ „ํžˆ ์ตํ˜€์ ธ์„œ snippet์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.


๐Ÿ‘‰๐Ÿป ๊ฒฐ๋ก ์ ์œผ๋กœ ๋ฆฌ์•กํŠธ๋ฅผ ์‚ฌ์šฉ์ž ์ค‘, ํ•จ์ˆ˜ ํ‘œํ˜„์‹ ๋“ฑ ์„ค์ • ์—†์ด ์Šค๋‹ˆํŽซ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์›ํ•œ๋‹ค๋ฉด ์•„๋ž˜ extension(ES7+ React/Redux/React-Native snippets)์„ ๋‹ค์šด๋ฐ›์•„ ์‚ฌ์šฉํ•˜์‹œ๊ธธ ๊ถŒ์žฅํ•œ๋‹ค.

ES7+ React/Redux/React-Native snippets

rafce๋ผ๋Š” ์Šค๋‹ˆํŽซ์€ ํ•จ์ˆ˜ ํ‘œํ˜„์‹์„ ๋น ๋ฅด๊ฒŒ ์ƒ์„ฑํ•ด์ฃผ์–ด ์ฝ”๋“œ์ƒ์‚ฐ์„ฑ์ด ๋น ๋ฅด๊ฒŒ ์ฆ๊ฐ€ํ•œ๋‹ค.

๐Ÿ‘‰๐Ÿป ๋งŒ์•ฝ ๋‹ค๋ฅธ ์Šค๋‹ˆํŽซ์„ ์„ค์ •ํ•˜๊ณ  ์‹ถ๊ฑฐ๋‚˜, ์Šค๋‹ˆํŽซ ๋‹จ์ถ•ํ‚ค๋ฅผ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด ๋” ์•„๋ž˜์— ์„ค์ •๋ฐฉ๋ฒ•์„ ์ž‘์„ฑํ•ด๋†จ๋‹ค.


Snippet ์‚ฌ์šฉ์žํ™”

๋งฅ๋ถ๊ธฐ์ค€ ๋‹จ์ถ•ํ‚ค command+p ๋ˆ„๋ฅด๊ณ  global-snippet-js.code-snippets ํŒŒ์ผ ํด๋ฆญํ•˜๊ธฐ

์ด์ œ ํŒŒ์ผ์—์„œ ์Šค๋‹ˆํŽซ์„ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค. console.log๋ฅผ cl์ด๋ผ๋Š” ์Šค๋‹ˆํŽซ์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์„ ๋ด๋ณด์ž.

"console.log": {
    "prefix": "cl",
    "body": ["console.log('$1');", "$2"],
    "description": "Log output to console"
},

 

prefix : ๋‹จ์ถ•ํ‚ค

body : ์‹ค์ œ ์ฝ”๋“œ

description : ์Šค๋‹ˆํŽซ ์„ค๋ช…

 

ํ…์ŠคํŠธ ์ปค์„œ

$1, $2์™€ ๊ฐ™์€ ๊ฒƒ๋“ค์€ ํ…์ŠคํŠธ ์ปค์„œ ์œ„์น˜ ์ด๋‹ค. 

${์ˆœ์„œ}๋กœ ์ž‘๋™ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ cl์„ ์ž…๋ ฅํ•˜๊ณ  ์—”ํ„ฐ๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ ()์‚ฌ์ด์— ์ปค์„œ๊ฐ€ ์œ„์น˜ํ•˜๊ฒŒ ๋œ๋‹ค. 

์Šค๋‹ˆํŽซ ๋ณ€์ˆ˜

๋‚˜๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด styled-components๊ฐ€ ๋“ค์–ด๊ฐ„ ํ•จ์ˆ˜ํ˜•์ปดํฌ๋„ŒํŠธ ์ฝ”๋“œ์˜ ๋ผˆ๋Œ€๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์—ˆ๋‹ค.

import { styled } from "styled-components";

function Title() {
	return <div></div>
}

export default Title;

 

๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•ด์„  ํŒŒ์ผ๋ช…์„ ๊ฐ€์ง€๊ณ  ์™€์•ผํ•˜๋Š”๋ฐ ์ด๋Š” ์Šค๋‹ˆํŽซ ๋ณ€์ˆ˜๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. 

์Šค๋‹ˆํŽซ ๋ณ€์ˆ˜๋“ค์€ ์•„๋ž˜์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ณ , ํŒŒ์ผ๋ช…์€ ${TM_FILENAME_BASE} ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. 

https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables

 

Snippets in Visual Studio Code

It is easy to add code snippets to Visual Studio Code both for your own use or to share with others on the public Extension Marketplace. TextMate .tmSnippets files are supported.

code.visualstudio.com

๊ทธ๋ž˜์„œ ๋งŒ๋“  ์Šค๋‹ˆํŽซ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

"Component with stytled-components": {
    "prefix": "rfs",
    "body": [
        "import { styled } from \"styled-components\";",
        "",
        "function ${TM_FILENAME_BASE}() {",
        "  return <div>${1}</div>",
        "}",
        "",
        "export default ${TM_FILENAME_BASE};"
    ],
    "description": "Component with stytled-components"
},

 

rfs๋ฅผ ๋ˆ„๋ฅด๋ฉด ์˜ˆ์˜๊ฒŒ ํŒŒ์ผ๋ช…์— ๋”ฐ๋ฅธ ์ฝ”๋“œ๊ฐ€ ๋œฐ๊ฒƒ์ด๋‹ค! ๐Ÿฅด