在命令行當中用VSCode 開啟一個資料夾,同時開啟一個檔案 + AutoHotkey 用 VSCode,Sublime開啟選中的檔案
阿新 • • 發佈:2021-08-04
Opening a Folder and File in Vscode from Terminal | JagaScript
code path_to_foder --goto path_to_file
AHK
注意把VSCode的根目錄新增到環境變數(並且用code.exe 呼叫),否則可能無法Run
CapsLock & s:: ; sublime folder := GetActiveExplorerPath() file := GetSelectedFilePath() if(folder != "") { Run, % "subl """ . file . """ -a """ . folder . """ ", , Hide, ; add folder } else if(file != "") { Run, % "subl """ . file . """" , Hide, ; without folder } Return CapsLock & v:: folder := GetActiveExplorerPath() file := GetSelectedFilePath() cmd := "code -n """ . file . """ -a """ . folder . """" if(folder != "") { ; Run, % "code" Run, % "code """ . folder . """ --goto """ . file . """", , Hide, ; add folder } else if(file != "") { Run, % "code -n """ . file . """" , Hide, ; without folder } ; code -n "D:\Data\Programs\UserData\Caesium\1.jpg" -a "D:\Data\Programs\UserData\Caesium" Return GetActiveExplorerPath() { explorerHwnd := WinActive("A") if (explorerHwnd) { for window in ComObjCreate("Shell.Application").Windows { if (window.hwnd==explorerHwnd) { folder := window.Document.Folder.Self.Path return folder } } } } GetSelectedFilePath() { hwnd := WinExist("A") for Window in ComObjCreate("Shell.Application").Windows if (window.hwnd==hwnd) { Selection := Window.Document.SelectedItems for Items in Selection Path_to_Selection := Items.path } Return Path_to_Selection }