3

任何使用 Visual Studio Code 的人都知道是否有办法在默认浏览器中右键单击并打开(例如 Sublime Text)?我知道您可以右键单击文件节点并“在资源管理器中显示”,然后在浏览器中手动打开它......但我想节省额外的 2 秒。

4

4 回答 4

4

实际上,上面的代码都打开了 Windows 文件资源管理器而不是 BROWSER。

我正在使用以下完美运行的代码,在 Chrome 中打开文件,同时使用 Javascript 测试静态 html 文件。

{
   "version": "0.1.0",
   "command": "Chrome",
   "windows": {
       "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
   },
   "args": ["${file}"]
}
于 2016-12-29T06:10:07.907 回答
3

我的一个项目中有类似的东西。我已经设置了我的 tasks.json,如下所示。有了它,我可以键入“Ctrl+P”然后键入“任务开始”并按 Enter 以在默认浏览器中加载当前的 HTML 文件 :-)

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
    "version": "0.1.0",
    "command": "powershell",
    "isShellCommand": true,
    "suppressTaskName": true,
    "tasks": [
        // other tasks here,
        {
            "taskName": "start browser",
            "args": [
                "start", "${file}"
            ]
        }
    ]
}
于 2015-07-01T20:28:50.480 回答
3

Ctrl+Shift+P并选择“配置任务运行程序”命令。它将使用不同类型的配置为您打开 tasks.json 文件。您可以删除所有这些,只需使用以下代码

{
    "version": "1.0.0",
    "command": "explorer",
    "windows": {
        "command": "explorer.exe"
    },
    "args": [
        "index.html"
    ]
}

不要担心命令“explorer”,这并不意味着它会在 Internet Explorer 中打开,它会在您的默认浏览器配置中打开。在参数中传递您想要打开的任何页面。

完成此操作后,只需按Ctrl+Shift+B,它将在您的默认浏览器中打开“index.html”页面。

于 2016-01-04T15:11:29.593 回答
0

添加到 Rafique Admed 答案,这是我的 tasks.json 文件:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "tasks": [
        {
            "taskName": "chrome",
            "command": "chrome",
            "windows": {
                "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
            },
            "args": ["${file}"]
        }
    ]
}

然后我将它添加到我的“keybindings.json”文件中:

[
    { "key": "ctrl+alt+b",
      "command": "workbench.action.tasks.runTask",
      "args": "chrome"
    }
]

用 ctrl+alt+b 打开当前编辑的文件(我选择 b 作为浏览器)。

于 2017-03-19T17:37:57.723 回答