VS Code snippets bụ ụzọ dị ike iji kwalite nrụpụta nzuzo gị site na ịmegharị ntinye nke ngọngọ koodu a na-ejikarị. Ha nwere ike ịbụ mgbasawanye ederede dị mfe ma ọ bụ ndebiri dị mgbagwoju anya nwere ndị na-edebe ebe na mgbanwe. Nke a bụ otu esi etinye ha:
Ịmepụta Snippets:
Nweta Ntọala Snippet: Gaa na faịlụ> Mmasị> Snippets onye ọrụ (koodu> Mmasị> Snippets onye ọrụ na macOS). N'aka nke ọzọ, jiri palette iwu (Ctrl+Shift+P ma ọ bụ Cmd+Shift+P) wee pịnye "Mmasị: Hazie Snippets Onye ọrụ".
Họrọ Asụsụ: A ga-akpali gị ịhọrọ asụsụ maka snippet gị (dịka, javascript.json, python.json, wdg). Nke a na-achọpụta na snippet dị naanị maka asụsụ ahụ akọwapụtara. Ị nwekwara ike ịmepụta faịlụ "Global Snippets" ma ọ bụrụ na ịchọrọ ka snippet ahụ dị n'asụsụ niile.
Kọwaa Snippet: A kọwapụtara snippet n'ụdị JSON. Snippet nke ọ bụla nwere aha, prefix (ụzọ mkpirisi ị ga-apịnye iji kpalite snippet), ahụ (koodu a ga-etinye), na nkọwa nhọrọ.
Ọmụmaatụ (JavaScript):
{
"For Loop": {
"prefix": "forl",
"body": [
"for (let i = 0; i < $1; i++) {",
" $0",
"}"
],
"description": "For loop with index"
}
}
N'ihe atụ a:
"Maka Loop": Aha nke snippet (maka ntụaka gị).
"forl": prefix. Ịpị "forl" na ịpị Tab ga-etinye snippet.
"body": Koodu itinye. $1, $2, wdg bụ tabstop (ndị jide ebe). $0 bụ ọnọdụ cursor ikpeazụ.
"nkọwa": Nkọwa nhọrọ egosiri na ntụnye IntelliSense.
Iji Snippets:
Pịnye prefix: N'ime faịlụ nke ụdị asụsụ ziri ezi, malite pịnye prefix ị kọwapụtara (dịka ọmụmaatụ, forl).
Họrọ Snippet: IntelliSense Code VS ga-atụ aro snippet. Jiri igodo akụ họrọ ya ma ọ bụ site na ịpị.
Jiri Tabstop: Pịa Tab ka ịnyagharịa n'etiti taabụ ($1, $2, wdg) wee dejupụta ụkpụrụ.
Mgbanwe:
Snippets nwekwara ike iji mgbanwe dị ka $TM_FILENAME, $CURRENT_YEAR, wdg. Maka ndepụta zuru ezu, hụ akwụkwọ VS Code.
Ọmụmaatụ nwere mgbanwe (Python):
{
"New Python File": {
"prefix": "newpy",
"body": [
"#!/usr/bin/env python3",
"# -*- coding: utf-8 -*-",
"",
"# ${TM_FILENAME}",
"# Created by: ${USER} on ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}"
]
}
}
Site n'ịghọta snippets, ị nwere ike ibelata mpịnye ugboro ugboro wee hụ na ọ dabara na koodu gị. Nnwale site na ịmepụta snippets nke gị maka ụkpụrụ koodu a na-ejikarị wee lelee arụmọrụ nzuzo gị na-arị elu.