问题
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