当前位置:  开发笔记 > 编程语言 > 正文

Sublime Text 2中的"智能引号"与LaTeXTools

如何解决《SublimeText2中的"智能引号"与LaTeXTools》经验,为你挑选了1个好方法。

我最近将我的LaTeX创作从TeXWorks迁移到Sublime Text 2,我真正缺少的一个功能是能够输入"常规引号",(在我的瑞典语键盘上使用shift+ 2,屈服"quoted text")并自动编辑将它们转换为在LaTeX中引用的正确方式,这是``quoted text''在我输入的时候.

我试图在ST2中寻找一种方法来做到这一点,但我发现的大部分内容都与自动转义字符串中的引号有关,这不是我所追求的.

有没有办法在ST2中获得此功能?



1> angerson..:

你可能能够让Sublime Text 2一次性完成编写它们,但是由于这可能涉及编写一个复杂的插件,为什么不重新映射"键来插入正确的字符呢?

可以添加模仿默认自动"配对的自定义键绑定,但在适当的位置插入LaTeX引号.将这些行(来自Preferences -> Key Bindings – Default第272-293行)添加到您的Preferences -> Key Bindings – User文件中:

{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "``$0''"}, "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
        { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true },
        { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true }
    ]
},

{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "``${0:$SELECTION}''"}, "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
    ]
},

{ "keys": ["\""], "command": "move", "args": {"by": "words", "forward": true}, "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^''", "match_all": true }
    ]
},

第一块代码覆盖了Sublime Text的默认引用配对,并将其调整为LaTeX样式的引号.当您"在LaTeX文件中键入a时,只要它位于通常会插入一组双引号的位置,您就会得到:

``|''

第二部分替换了使用引号自动封闭所选文本的默认功能.在LaTeX文件中,选择文本然后按"将导致:

``This is the text you selected|''

''"插入符号与插入符号相邻时,最后的重新绑定会跳过结束引号().也就是说,当你按下"这里时:

``Sublime Text is the best!|''

插入符号将移出引号之外,如下所示:

``Sublime Text is the best!''|

推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有