简体   繁体   English

如何设置密钥以在没有任何扩展名的情况下在浏览器中打开 html 文件?

[英]How do I set a key to open html file in browser in vscode without any extension?

I know there are few extensions available in vscode to open html files in browser.我知道 vscode 中有几个扩展可以在浏览器中打开 html 文件。 But I don't want to use any of them.但我不想使用它们中的任何一个。 I'd love to learn how to set a key, say "F12" to open html files in default browser.我很想学习如何设置一个键,说“F12”以在默认浏览器中打开 html 个文件。

For example with this key binding code below, we can do the exact same in Sublime text例如,使用下面的键绑定代码,我们可以在 Sublime text 中执行完全相同的操作

{ "keys": ["f12"], "command": "open_in_browser"}

Btw, I've tried this but it asks for questions every time instead of opening the.html in browser directly.顺便说一句,我已经试过了,但它每次都会询问问题,而不是直接在浏览器中打开 .html。 - https://gist.github.com/borekb/269391102b75c4196a811dd805336dd5#file-tasks-json - https://gist.github.com/borekb/269391102b75c4196a811dd805336dd5#file-tasks-json

Does anyone know how I can set the key F12 in vscode to open.html files in browser?有谁知道我如何在vscode中设置F12键以在浏览器中打开 .html 文件?

Thanks in advance.提前致谢。

The given example (copied from the page you provided) is wrong.给定的示例(从您提供的页面复制)是错误的。

{
  "version": "0.1.0",
  "command": "Chrome Canary",
  "windows": {
    "command": "C:\\Users\\borek\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"
  },
  "args": ["${file}"]
}

You should replace the top level "command" with "label" .您应该将顶级"command"替换为"label" Not only that, but each task must be part of the "tasks" array.不仅如此,每个任务都必须是"tasks"数组的一部分。 Thus the whole thing becomes as follows:于是整个事情就变成了下面这样:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Chrome Canary",
      "windows": {
        "command": "C:\\Users\\borek\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"
      },
      "args": ["${file}"]
    }
  ]
}

After that you can add the following to your keybindings.json :之后,您可以将以下内容添加到您的keybindings.json

{
  "key": "ctrl+alt+shift+c",
  "command": "workbench.action.tasks.runTask",
  "args": "Chrome Canary"
}

You can open the tasks.json in VSCode and edit it right there - VSCode will give you suggestions.你可以在 VSCode 中打开tasks.json并在那里编辑它——VSCode 会给你建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM