简体   繁体   English

VS Code - 键绑定 - 我自己的块注释

[英]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.

相关问题 VS Code:重新包装文本或注释块 - VS Code: Rewrap block of text or comment 在VS代码中分别更改注释和块注释colors - Change comment and block comment colors separately in VS code VS Code:select 的快捷方式或删除没有选择文本的块注释 - VS Code: Shortcut to select or remove Block Comment with no text selected 使 Visual Studio 使用 VS 代码快捷键/键绑定 - Make Visual Studio use VS code shortcut keys / key bindings VS 代码 - 键绑定 - *type* 命令的 cursor position - VS Code - Key bindings - cursor position for *type* command 如何在 React (JavaScript) 中使用单行注释符号 // not /* 进行块注释<app><home /></app> } */ 在 VS 代码中 - How can I make a block comment in React (JavaScript) use single line comment notation of // not /* <App><Home /></App>} */ in VS Code 通过 VS Code 中的热键运行 Rspec 块 - Run Rspec block via hot key in VS Code 如何为 vs code 创建自己的主题? - How can I create my own theme for vs code? 如何在 vs code 中选择自己的构建文件? - How can I choose my own build file in vs code? 为什么Shift / Alt键盘组合可用于默认绑定,但不适用于我的自定义绑定? (VS代码) - Why does shift/alt keyboard combination work for default bindings but not my custom ones? (VS Code)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM