首页 > 解决方案 > php中语言为html且前面的文本匹配正则表达式时的Vscode键绑定

问题描述

我正在尝试从 sublime 迁移到 vscode,但不知道如何移动我的一些 keybindigs。其中之一是“=”,<?=$1?>当我在 php 文件中编辑 html 代码时插入。更重要的是,我已经将它配置为匹配前面的一些文本,因此它不会插入“=”,属性<img src=""/>将按原样显示。在崇高它被配置为

{ "keys": ["="], "command": "run_macro_file", "args": {"file": "res://Packages/User/macro/php/quick_echo_php.sublime-macro"}, "context":[
    {"key": "selector", "operator": "equal", "operand": "embedding.php", "match_all":true},
    {"key": "selector", "operator": "not_equal", "operand": "meta.embedded.line.php", "match_all":true},
    {"key": "selector", "operator": "not_equal", "operand": "source.php", "match_all":true},
    {"key": "selector", "operator": "not_equal", "operand": "source.js.embedded.html", "match_all":true},
    {"key": "selector", "operator": "not_equal", "operand": "punctuation.definition.tag.end.html", "match_all":true},
    {"key": "preceding_text", "operator": "not_regex_match", "operand": ".*<"},
    {"key": "preceding_text", "operator": "not_regex_match", "operand": ".*\\?"},
    {"key": "preceding_text", "operator": "not_regex_match", "operand": ".*[a-zA-Zа-яА-Я]+"},
    {"key": "setting.command_mode", "operand": false}
]},

在 vscode 中,我结束的是

{
    "key": "=",
    "command": "editor.action.insertSnippet",
    "args": {"snippet": "<?=$1?>"},
    "when": "vim.active && !inDebugRepl && vim.mode == Insert && editorLangId =~ /php|html/"
},

很明显这是没用的,因为“=”在所有 php 中都是非常必要的符号,例如$a = 1;

我在“开发人员:检查上下文键”中没有发现任何有用的东西。我什至尝试在 php 文件中聚焦 html 行之后在 vscode 开发控制台中按 ctrl+f "html" 并在那里看到零匹配。我只是找不到 keybindigs 的范围,但它存在于片段中。

PS "langId"in"args"对以太没有帮助。

标签: visual-studio-codevscode-keybinding

解决方案


推荐阅读