我只是在 一个名为 run_multiple_commands.py 的插件的帮助下部分实现了这个功能(见下文)
(仅在 ST3 上测试过,但该插件早于 ST3 的第一个版本,应该也可以在 ST2 上运行)。
快捷键配置如下:
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move", "args": {"by": "characters", "forward": true} }
]
},
"context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move", "args": {"by": "characters", "forward": true} },
]
},
"context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move_to", "args": {"to": "brackets"} },
]
},
"context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[(\\[{]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["shift+space"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move_to", "args": {"to": "brackets"} },
{"command": "move", "args": {"by": "characters", "forward": true} },
]
},
"context":
[
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^[(\\[{]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
四个条件的一个快捷方式(shift+space):
-
光标就在引号或右括号/括号之后:
向前移动一个字符
-
光标就在引号或右括号/括号之前:
向前移动一个字符
-
光标就在左括号/括号之前:
移至右括号/括号
-
!1 && !2 && !3:
移动到右括号/括号
再向前移动一个字符
要在你的ST中使用这个配置,你应该先在你的.../Package/User/目录下添加一个名为run_multiple_commands.py的文件,其内容是This Article的第二段代码
此解决方案适合日常使用,但并不完美,因为:
- 光标无法跳出引号(光标直接跟在一个引号后才跳过)。
- 注释代码块时,光标无法跳出最近的圆括号、引号或方括号。