VSCode 自定义宏

nee*_*dle 5 macros latex keyboard-shortcuts visual-studio-code

我目前正在尝试使用 VSCode,但我不知道如何正确定义宏并将它们绑定到特定的按键绑定。

我习惯使用 Sublime text,并且我定义了一些宏,可以帮助我更快地打字并减少错误

我想要获得的宏如下:

  1. alt+shift+q:键入\(\)并将光标设置在中间(第一个(和第二个之间\)。
  2. alt+shift+s:键入\[\]并将光标设置在中间(第一个[和第二个之间\)。此外,如果可能的话,我希望它也可以使用 切换数学预览功能latex-workshop.toggleMathPreviewPanel
  3. alt+shift+a:输入以下内容
\begin{align*}
    \item 
\end{align*}
Run Code Online (Sandbox Code Playgroud)

\item前面有 a ,tab它将光标设置在\item

我已经通过执行以下操作成功获得了第一个宏

  • 通过 geddski 安装宏包。
  • 创建以下宏,并将其插入到settings.json
"macros": {
        "latex_inline_math": [
            {
                "command": "type",
                "args": {
                    "text": "\\(\\)"
                }
            },
            "cursorLeft",
            "cursorLeft"
        ],
}
Run Code Online (Sandbox Code Playgroud)
  • 通过插入以下内容将其绑定到按键绑定keybindings.json
{ // to get \(\)
    "key": "alt+shift+q",
    "command": "macros.latex_inline_math"
},
Run Code Online (Sandbox Code Playgroud)

但我不知道如何获取宏 2. 和 3.

另外,如果有更好的方法来编写我编写的宏,请告诉我

rio*_*oV8 7

您可以定义以下 3 个键绑定

  {
    "key": "shift+alt+q",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": { "snippet": "\\($0\\)" }
  },
  {
    "key": "shift+alt+s",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": { "snippet": "\\[$0\\]" }
  },
  {
    "key": "shift+alt+a",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": { "snippet": "\\begin{align*}\n\t\\item$0\n\\end{align*}" }
  }
Run Code Online (Sandbox Code Playgroud)

如果您还想要预览,可以使用扩展多重命令

定义此键绑定

  
{
    "key": "shift+alt+s",
    "command": "extension.multiCommand.execute",
    "args": { 
        "sequence": [
            "latex-workshop.toggleMathPreviewPanel",
            { "command": "editor.action.insertSnippet", "args": { "snippet": "\\[$0\\]" } }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)