问题描述
我正在使用atom作为.tex文档的主要编辑器.方括号匹配器软件包给我提供的一个功能是,我每次输入开头{时,它都会自动插入一个结束符}.我想为$添加一个类似的功能,因为我经常最终在乳胶中使用mathmode.我在哪里可以添加呢?我不想将其添加到摘要中,在这里我必须按tab才能显示另一个$.我只想在我每次打开$时自动添加第二个结束$(在光标之后).如果可以通过仅在.tex文件上启用该设置的设置来做到这一点,那就太好了.
I am using atom as my main editor for .tex documents. A feature which the bracket-matcher package gives that I really like is that it automatically inserts a closing }, any time I enter an opening {. I would like to add a similar feature for $, as I often end up using mathmode in latex. Where would I be able to add this? I do not want to add it in a snippet, where I would have to press tab for another $ to appear. I would simply like for a second closing $ to be automatically added (after my cursor) whenever I do open one. If this can be done with a setting that makes it enabled only on .tex files, that would be great.
推荐答案
由于标准代码段不会在单个按键上触发,因此您必须以编程方式解决此问题.您将必须编辑以下两个文件.
Since a standard snippet won't trigger on a single key-press, you will have to solve this programmatically. You will have to edit the following two files.
i.初始化脚本( init.coffee
或 init.js
):
i. Init Script (init.coffee
or init.js
):
atom.commands.add 'atom-text-editor', 'custom:insert-dollar-pair', ->
snippetBody = '\$ $1 \$$0'
atom.packages.activePackages.snippets?.mainModule?.insert snippetBody
ii.键映射( keymap.cson
或 keymap.json
):
ii. Keymap (keymap.cson
or keymap.json
):
'atom-text-editor[data-grammar="text tex latex"]':
'\$': 'unset!'
'\$': 'custom:insert-dollar-pair'
PS:我认为您甚至不必逃避美元符号,但这可以实现良好的视觉分隔.
PS: I think you don't even have to escape the dollar-sign, but it makes for good visual separation.
这篇关于我在哪里可以在原子编辑器中添加自己的自动完成代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!