🆚
【VSCode】ショートカットで任意のファイルを開く
対象読者
- VSCodeでweb開発を行う人
- logファイルや
docker-compose.ymlを探すのが面倒な人 - 複数のプロジェクト(リポジトリ)で作業する人
概要
VSCodeで特定のファイルをショートカットで開く設定を紹介します。
例) Ctrl + L で プロジェクトのlogファイルを開く
基本的にはこちらのqiita記事を参考にしています。
応用項目にて、複数プロジェクトにまたがって設定する方法を記載しています。
環境
| 項目 | バージョン |
|---|---|
| Version | 1.95.1 (Universal) |
| Commit | 65edc4939843c90c34d61f4ce11704f09d3e5cb6 |
| Date | 2024-10-31T05:14:54.222Z |
| Electron | 32.2.1 |
| ElectronBuildId | 10427718 |
| OS | Darwin arm64 23.2.0 |
手順
プロジェクトを開く
Open Folderなどからプロジェクトを開く

tasks.jsonの作成
-
VSCodeで
Cmd + Shift + Pを押し、Tasks: Configure Taskを選択

-
Create tasks.json file from templateを選択

-
Othersを選択

-
{現在開いているパス}.vscode/tasks.jsonが作成されるので、以下のように編集
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "openLog",
"type": "shell",
"command": "code path/to/logfile.log",
},
]
}
keybindings.jsonの作成
-
VSCodeで
Cmd + Shift + Pを押し、Preferences: Open Keyboard Shortcuts (JSON)を選択

-
ローカルに
keybindings.jsonが開かれるので、以下のように編集
keybindings.json
[
{
"key": "ctrl+l",
"command": "workbench.action.tasks.runTask",
"args": "openLog" // tasks.jsonのlabel
}
]
応用: 複数のプロジェクトで使う
- VSCodeで
Cmd + Shift + Pを押し、Tasks: Configure Taskを選択 - Create tasks.json file from templateを選択
- Othersを選択
path/to/logfile.logをプロジェクトによって変更させることで、複数のプロジェクトで使うことができます。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "openLog",
"type": "shell",
"command": "code other/path/to/logfile.log", // プロジェクトごとにlogファイルを変更
},
]
}
応用2: docker-compose.ymlを開く
- tasks.jsonを以下のように追加
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "openLog",
"type": "shell",
"command": "code path/to/logfile.log",
},
// ここから追加
{
"label": "openDockerCompose",
"type": "shell",
"command": "code path/to/docker-compose.yml",
},
// ここまで追加
]
}
- keybindings.jsonを以下のように追加
keybindings.json
[
{
"key": "ctrl+l",
"command": "workbench.action.tasks.runTask",
"args": "openLog"
},
// ここから追加
{
"key": "ctrl+d", // 任意のショートカットキー
"command": "workbench.action.tasks.runTask",
"args": "openDockerCompose"
}
// ここまで追加
]
まとめ
ショートカットキーにはお好み。
ctrl + d は他のショートカットと被りそうなので、要検討。
Discussion