【发布时间】:2019-05-29 12:37:02
【问题描述】:
这是自动配对星号(用于 Markdown 和 AsciiDoc)文件的键盘映射。有用。问题:
1) 我应该或不应该在第 1 块的第 6 行转义星号吗?
2) 在我的测试中,这一行中的转义没有任何区别。但为什么?如果您尝试在最后一个块的第 5 行和第 6 行(以及第 5 个块中的行)中删除转义,则会导致不正确的行为。所以,这里需要转义 。但似乎第一个街区不需要它。这让我很困惑。
[
// Auto-pair *
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*$0*"}, "context":
[
{ "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 }, // --- THIS line ---
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.other - punctuation.definition.string.end", "match_all": true }
]
},
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*${0:$SELECTION}*"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
},
{ "keys": ["*"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "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 }, // --- THIS line ---
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.other - punctuation.definition.string.end", "match_all": true },
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\*$", "match_all": true }, // --- THIS line ---
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true }, // --- THIS line ---
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.other - punctuation.definition.string.end", "match_all": true },
]
},
]
更新:实际上,使用另一个正则表达式会更好:
- [*a-zA-Z0-9_]$
+ (^[*\\s]*$)|([*a-zA-Z0-9_]$)
这样,当您使用项目符号列表时,星号不会在行首重复。
【问题讨论】:
标签: regex escaping sublimetext3 sublimetext