
알-슈타인문서 클래스(예: 비머 또는 기사)에 특정한 컨텍스트 측면에서 키 바인딩을 정의할 수 있는 방법을 설명했습니다. 스니펫에 대해 어떻게 동일한 작업을 수행할 수 있습니까?
MWE:
<snippet>
<content><![CDATA[
\alert{$1} $0
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>test</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>latextools.documentclass.article</scope>
</snippet>
답변1
스니펫에 대해서는 임의의 컨텍스트를 작성할 수 없고 범위만 작성할 수 있습니다. 따라서 이에 대한 스니펫을 만들 수 없습니다. 그러나 키에 대한 키 바인딩을 생성하여 스니펫 동작을 에뮬레이트할 수 있습니다 tab
. 이는 캐럿 앞의 텍스트가 test
. 이 키 바인딩은 앞에 있는 단어를 제거하고 코드 조각을 삽입해야 합니다. "Chain Of Command" 패키지를 설치하는 경우 다음 키 바인딩을 사용할 수 있습니다.
{
"keys": ["tab"],
"command": "chain",
"args": {"commands": [
["delete_word", {"forward": false}],
["insert_snippet", {"contents": "\\alert{$1} "}],
]},
"context":
[
{ "key": "selector", "operand": "text.tex.latex" },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\btest$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "latextools.documentclass", "operand": "article" },
]
},
"operand": "\\btest$",
정규식을 다음으로 변경하여 조정할 수 있습니다 ."operand": "\\byour_trigger$",