snippets Code VS hanya ce mai ƙarfi don haɓaka haɓaka aikin coding ta atomatik shigar da tubalan lambobin da aka saba amfani da su. Zasu iya zama sassauƙan faɗaɗa rubutu ko ƙarin hadaddun samfura tare da masu riƙe wuri da masu canji. Ga yadda ake amfani da su:
Ƙirƙirar Snippets:
Samun dama ga Saitunan Snippet: Je zuwa Fayil> Zaɓuɓɓuka> Snippets masu amfani (Lambar> Zaɓuɓɓuka> Snippets mai amfani akan macOS). A madadin, yi amfani da palette na umarni (Ctrl+Shift+P ko Cmd+Shift+P) kuma rubuta "Preferences: Configure User Snippets".
Zaɓi Harshe: Za a sa ku zaɓi yare don gunkin ku (misali, javascript.json, python.json, da sauransu). Wannan yana tabbatar da snippet ɗin yana samuwa kawai don takamaiman harshe. Hakanan zaka iya ƙirƙirar fayil ɗin "Global Snippets" idan kuna son snippet ɗin ya zama mai isa ga duk harsuna.
Ƙayyade Snippet: An bayyana snippets a tsarin JSON. Kowane snippet yana da suna, prefix ( gajeriyar hanyar da za ku rubuta don jawo snippet), jiki (lambar da za a saka), da bayanin zaɓi na zaɓi.
Misali (JavaScript):
{
"For Loop": {
"prefix": "forl",
"body": [
"for (let i = 0; i < $1; i++) {",
" $0",
"}"
],
"description": "For loop with index"
}
}
A cikin wannan misali:
"Don Loop": Sunan snippet (don bayanin ku).
"forl": prefix. Buga "forl" da latsa Tab zai saka snippet.
"jiki": Lambar da za a saka. $1, $2, da dai sauransu su ne tashoshi (masu sanya wuri). $0 shine matsayi na ƙarshe.
"bayani": Bayanin zaɓi wanda aka nuna a cikin shawarwarin IntelliSense.
Amfani da Snippets:
Buga Prefix: A cikin fayil na nau'in yare daidai, fara buga prefix ɗin da kuka ayyana (misali, forl).
Zaɓi Snippet: IntelliSense na Code VS zai ba da shawarar snippet. Zaɓi shi tare da maɓallan kibiya ko ta dannawa.
Yi amfani da Tashoshi: Latsa Tab don kewaya tsakanin shafuka ($1, $2, da sauransu) kuma cika ƙimar.
Daban-daban:
Snippets kuma na iya amfani da masu canji kamar $TM_FILENAME, $CURRENT_YEAR, da sauransu. Don cikakken jeri, duba takaddun VS Code.
Misali tare da Canje-canje (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}"
]
}
}
Ta hanyar ƙware snippets, zaku iya rage yawan maimaita bugawa da tabbatar da daidaito a lambar ku. Gwaji tare da ƙirƙirar snippets na kanku don tsarin lambobin da aka saba amfani da su kuma kalli yadda ingancin coding ɗinku ya ƙaru.