[英]VS Code - Key Bindings - my own Block comment
I am using VS Code Version: 1.40.0.我正在使用 VS 代码版本:1.40.0。
for quicken up my development I would need to set my own keybinding for block comment when I am in .phtml file.为了加快我的开发速度,当我在.phtml文件中时,我需要为块注释设置自己的键绑定。
I managed to get into keybindings.json , put this inside:我设法进入keybindings.json ,把这个放在里面:
{
"key": "shift+alt+q",
"command": "editor.action.blockComment",
"blockComment": [ "{*<!--", "-->*}" ],
"when": "editorTextFocus && !editorReadonly && resourceExtname == .phtml"
}
I got the part我得到了这个部分
"blockComment": [ "{*<!--", "-->*}" ],
from here How to customize comment block characters in visual studio code?从这里如何在 Visual Studio 代码中自定义注释块字符? .
.
It might be a complete trash.这可能是一个彻头彻尾的垃圾。 I just tried.
我刚试过。 It doesn't work, of course.
当然,它不起作用。
Optimal solution: Even better would be, if the default key parameter would stay the same ( shift+alt+a ) for toggle block comment and in .phtml files i would get my desired result (" {*<!-- -->*}
").最佳解决方案:更好的是,如果切换块注释的默认键参数保持不变( shift+alt+a ),并且在.phtml文件中,我会得到我想要的结果(“
{*<!-- -->*}
”)。 If I think about it, there is default block comments for .css , .html etc, so there must be a way to put my condition somewhere, rigth?如果我考虑一下, .css , .html等有默认的块注释,所以必须有办法将我的条件放在某个地方,对吗?
I would be very glad for any help.我会很高兴得到任何帮助。 Thanks in advance
提前致谢
As far as I know the best would be to write your own Language Extension plugin for.phtml files and set the desired comment pairs in its configuration .据我所知,最好的方法是为.phtml 文件编写您自己的 语言扩展插件,并在其配置中设置所需的注释对。
Not a real solution but until then, here's my supper ugly workaround (use at your own risk):这不是一个真正的解决方案,但在那之前,这是我的超级丑陋的解决方法(使用风险自负):
Put this in your keybindings.json把它放在你的键绑定中。json
{
"key": "ctrl+numpad_divide",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "${TM_SELECTED_TEXT/^(\\s*)({\\*<!-- (.*) -->\\*})?(.*)/$1${3:-{*<!-- }$4${4:+ -->*\\}}/s}"
},
"when": "editorTextFocus && editorHasSelection && !editorReadonly && resourceExtname =~ /phtml?$/"
}
This way ctrl + /
can be used for comment/uncomment (toggle) the selected code as you described.这种方式
ctrl + /
可用于注释/取消注释(切换)您描述的所选代码。 Of course you can set the key binding to something else like alt + /
to keep the default block comment behaviour.当然,您可以将键绑定设置为
alt + /
之类的其他内容,以保持默认的块注释行为。
Tested with Visual Studio Code v1.50.1使用 Visual Studio Code v1.50.1 测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.