Convert - -(double dash) to -> automatically in SublimeText 3

社会主义新天地 提交于 2021-02-08 12:02:29

问题


During my work I use -> many times and on a hungarian keyboard there is no dedicated > button, so I have to use 3 keys to enter this and sometimes I also misstype. Is there a way to convert -- (double dash) automatically a ->? Snippet is not so good because it requires a TAB to convert. Thanks


回答1:


It's possible to do this with a simple key binding such as the following:

{
    "keys": ["-", "-"],
    "command": "insert", "args": {
        "characters": "->"
    },
},

Now when you type -- as soon as you hit the second - it triggers and replaces the text with -> like you want.

Note however that this would apply to every usage of the text -- in every file. This could be constrained to some degree by using a context in the key binding that makes it apply only in certain files, such as this one that ensures that the binding is only valid in plain text files:

{
    "keys": ["-", "-"],
    "command": "insert", "args": {
        "characters": "->"
    },
    "context": [
        { 
            "key": "selector", 
            "operator": "equal", 
            "operand": "text.plain", 
            "match_all": true 
        },

    ],
},

This can be applied to any scope you want; use Tools > Developer > Show Scope Name... from the menu while editing a file to determine the scope that you need (generally you probably want only the first scope item).

Either way, this makes it impossible to type -- directly without including a deliberate long pause between the two - characters or doing a backspace. That may or may not be an issue.



来源:https://stackoverflow.com/questions/52872467/convert-double-dash-to-automatically-in-sublimetext-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!