Li-Snippets tsa VS Code ke mokhoa o matla oa ho holisa tlhahiso ea likhoutu ka ho kenya li-block tsa khoutu tse sebelisoang hangata. E ka ba litlatsetso tse bonolo tsa mongolo kapa lithempleite tse rarahaneng tse nang le litšoantšiso le mefuta e fapaneng. Mona ke mokhoa oa ho li sebelisa:
Ho theha Lipotso:
Fumana Litlhophiso tsa Snippet: Eya ho Faele> Likhetho> Linotsoana tsa Basebelisi (Khoutu> Likhetho> Lipotso tsa mosebelisi ho macOS). Ntle le moo, sebelisa phalete ea taelo (Ctrl+Shift+P kapa Cmd+Shift+P) 'me u thaepe "Likhetho: Lokisa Likotoana tsa Basebelisi".
Khetha Puo: U tla susumelletseha ho khetha puo bakeng sa snippet ea hau (mohlala, javascript.json, python.json, joalo-joalo). Sena se tiisa hore snippet e fumaneha feela bakeng sa puo e itseng. U ka boela ua etsa faele ea "Global Snippets" haeba u batla hore snippet e fumanehe lipuong tsohle.
Hlalosa Snippet: Lipotso li hlalosoa ka sebopeho sa JSON. Pono e 'ngoe le e 'ngoe e na le lebitso, sehlongoapele (tsela e khaoletsoang eo u tla e thaepa ho qala snippet), 'mele (khoutu e tla kengoa), le tlhaloso ea boikhethelo.
Mohlala (JavaScript):
{
"For Loop": {
"prefix": "forl",
"body": [
"for (let i = 0; i < $1; i++) {",
" $0",
"}"
],
"description": "For loop with index"
}
}
Mohlala ona:
"For Loop": Lebitso la snippet (bakeng sa referense ea hau).
"forl": Sehlongoapele. Ho ngola "forl" le ho tobetsa Tab ho tla kenya snippet.
"body": Khoutu eo o lokelang ho e kenya. $1, $2, joalo-joalo ke li-tabstops (litšoantšiso tsa sebaka). $0 ke sebaka sa ho qetela sa sekhesa.
"Descript": Tlhaloso ea boikhethelo e bonts'itsoeng litlhahisong tsa IntelliSense.
Ho sebelisa Snippets:
Tlanya Sehlomapele: Faeleng ea mofuta o nepahetseng oa puo, qala ho thaepa sehlongoapele seo u se hlalositseng (mohlala, forl).
Khetha Snippet: IntelliSense ea VS Code e tla fana ka tlhahiso ea snippet. E khethe ka linotlolo tsa metsu kapa ka ho tobetsa.
Sebelisa Li-Tabstops: Tobetsa Tab ho tsamaea lipakeng tsa li-tabstops ($1, $2, joalo-joalo) ebe u tlatsa boleng.
Mefuta e fapaneng:
Li-Snippets li ka boela tsa sebelisa lintho tse fapaneng tse kang $TM_FILENAME, $CURRENT_YEAR, joalo-joalo. Bakeng sa lenane le feletseng, sheba litokomane tsa VS Code.
Mohlala ka mefuta e fapaneng (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}"
]
}
}
Ka ho tseba linepe, o ka fokotsa haholo ho thaepa khafetsa le ho etsa bonnete ba hore khoutu ea hau e lumellana. Leka ho iketsetsa linepe bakeng sa lipaterone tsa khoutu tse sebelisoang hangata 'me u shebelle bokhoni ba hau ba ho ngola bo ntse bo phahama.