사용자 도구

사이트 도구


wiki:util:vscode:vs_code_사용자_snippets_만들기_-_html

VS Code 사용자 snippets 만들기 - html

  • description : VS Code 사용자 snippets 만들기 - html
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2021-07-15 Thu


Snippet

코드 자동 완성 기능

HTML

VS Code에서 확장자 html를 가진 파일을 만든 후 첫 라인에 ! (느낌표)를 입력하면,
Tab 키 또는 Enter키를 누르면 하기와 같은 기본 html 서식 문서가 작성됩니다.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
 
</body>
</html>

사용자 snippets 만들기

1. File > Preferences > User Snippets - 검색창에 html.json을 입력 후 Enter를 클릭합니다.

( 파일 > 설정 > '사용자 코드 조각' )\\


2. 기본 저장된 파일의 내용은 하기와 같으며, snippets를 만들기 위한 가이드 내용입니다.
(수정 전)

{
	// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. 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": {
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
}


(수정 후)

{
  "korean html form" : {
    "prefix": "korean-html-form",
    "body": [
      "<!DOCTYPE HTML>",
      "<html lang=\"ko\">",
      "<head>",
	"<meta charset=\"UTF-8\">",
	"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no\">",
	"<title>${1:제목을 입력하세요}</title>",
      "</head>",
    "<body>",
      "$2",
    "</body>",
    "</html>"
    ],
    "description": "html auto-complete for Korean"
  }	
}


상기 html.json 파일을 저장 후, prefix로 지정한 “korean-html-form”을 입력(자동완성이 됩니다)하고
Tab 또는 Enter를 클릭하면, 하기와 같이 기본 html 서식 문서가 생성됩니다.

<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title>제목을 입력하세요</title>
</head>
<body>
 
</body>
</html>


$1, $2는 자동 완성이 된 후, 옮겨지는 커서의 순서를 가리킵니다.
첫 번째는 title 태그로 커서가 옮겨지고, title 태그에 내용 입력 후 Tab키를 누르면,
body안에 있는 $2의 위치로 커서가 이동합니다.

html snippet 파일 저장 위치 :
C:\Users\[user name]\AppData\Roaming\Code\User\snippets\

Ref

/var/services/web/dokuwiki/data/pages/wiki/util/vscode/vs_code_사용자_snippets_만들기_-_html.txt · 마지막으로 수정됨: 2023/01/13 18:44 (바깥 편집)