簡體   English   中英

如何設置密鑰以在沒有任何擴展名的情況下在瀏覽器中打開 html 文件?

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

我知道 vscode 中有幾個擴展可以在瀏覽器中打開 html 文件。 但我不想使用它們中的任何一個。 我很想學習如何設置一個鍵,說“F12”以在默認瀏覽器中打開 html 個文件。

例如,使用下面的鍵綁定代碼,我們可以在 Sublime text 中執行完全相同的操作

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

順便說一句,我已經試過了,但它每次都會詢問問題,而不是直接在瀏覽器中打開 .html。 - https://gist.github.com/borekb/269391102b75c4196a811dd805336dd5#file-tasks-json

有誰知道我如何在vscode中設置F12鍵以在瀏覽器中打開 .html 文件?

提前致謝。

給定的示例(從您提供的頁面復制)是錯誤的。

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

您應該將頂級"command"替換為"label" 不僅如此,每個任務都必須是"tasks"數組的一部分。 於是整個事情就變成了下面這樣:

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

之后,您可以將以下內容添加到您的keybindings.json

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

你可以在 VSCode 中打開tasks.json並在那里編輯它——VSCode 會給你建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM