最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

vscode extensions - Create a shortcut to open multiple files and keep them open in Visual Studio Code - Stack Overflow

matteradmin2PV0评论

I have a task that I do several times a day everyday that requires editing 20 files (spread out in different places throughout my project), keeping them open since editing each file mostly requires referring back to 1 or several of the other files multiple times.

I want to create a shortcut that opens these 20 files at once so that I can edit them, without navigating to the location of each file, as this becomes slightly tedious due to how often I have to do this task.

However, I frequently use the preview mode when coding & so don't want to disable preview mode altogether via setting "workbench.editor.enablePreview": false in my settings file.

I also don't want to relocate the files into 1 place, as this would break the general anisation of the project - unless there's a way to create an alias/shortcut of a file in a different location, that can open the file while not moving the actual file from its original location.

I used the top answer from this question to create the below macro. However, this macro only opens each file in preview mode - every time the next file is opened, the previous file is closed, & so the macro essentially only opens the last file in preview mode.

const vscode = require('vscode');

module.exports.macroCommands = {
   OpenFrequentFiles: {
      no: 1,
      func: () => openFrequentFiles()
   },
};

function openFrequentFiles() {

    const workspaceDir = ""/full/path/to/my/workspace"
    const frequentFilepaths = [
        "path/to/file1",
        "path/to/file2",
        ...
        "path/to/file20",
    ]
    for (let i = 0; i < frequentFilepaths.length; i++) {
        fullFilepath = workspaceDir + '/' + frequentFilepaths[i];
        openFile(fullFilepath);
    }
}

function openFile(filename) {
  const document = vscode.workspace.openTextDocument(filename);
  const editor = vscode.window.showTextDocument(document);
}

Is there are way to open the files & keep them open, instead of only opening each one briefly in period mode? I've looked through & tried to write something along the lines of workbench.action.keepEditor, but I haven't managed to make it work.

Or any other suggestions would be great - it would just save me time & tedium in the long term if I could automate the opening of these files without navigating to each one.

I have a task that I do several times a day everyday that requires editing 20 files (spread out in different places throughout my project), keeping them open since editing each file mostly requires referring back to 1 or several of the other files multiple times.

I want to create a shortcut that opens these 20 files at once so that I can edit them, without navigating to the location of each file, as this becomes slightly tedious due to how often I have to do this task.

However, I frequently use the preview mode when coding & so don't want to disable preview mode altogether via setting "workbench.editor.enablePreview": false in my settings file.

I also don't want to relocate the files into 1 place, as this would break the general anisation of the project - unless there's a way to create an alias/shortcut of a file in a different location, that can open the file while not moving the actual file from its original location.

I used the top answer from this question to create the below macro. However, this macro only opens each file in preview mode - every time the next file is opened, the previous file is closed, & so the macro essentially only opens the last file in preview mode.

const vscode = require('vscode');

module.exports.macroCommands = {
   OpenFrequentFiles: {
      no: 1,
      func: () => openFrequentFiles()
   },
};

function openFrequentFiles() {

    const workspaceDir = ""/full/path/to/my/workspace"
    const frequentFilepaths = [
        "path/to/file1",
        "path/to/file2",
        ...
        "path/to/file20",
    ]
    for (let i = 0; i < frequentFilepaths.length; i++) {
        fullFilepath = workspaceDir + '/' + frequentFilepaths[i];
        openFile(fullFilepath);
    }
}

function openFile(filename) {
  const document = vscode.workspace.openTextDocument(filename);
  const editor = vscode.window.showTextDocument(document);
}

Is there are way to open the files & keep them open, instead of only opening each one briefly in period mode? I've looked through https://code.visualstudio/api/references/vscode-api & tried to write something along the lines of workbench.action.keepEditor, but I haven't managed to make it work.

Or any other suggestions would be great - it would just save me time & tedium in the long term if I could automate the opening of these files without navigating to each one.

Share Improve this question asked Nov 18, 2024 at 11:35 domgunewardenadomgunewardena 12 bronze badges 2
  • you can use the extension I wrote: File Group – rioV8 Commented Nov 18, 2024 at 12:27
  • Exactly what I was looking for @rioV8 - thanks so much! – domgunewardena Commented Nov 18, 2024 at 14:07
Add a comment  | 

1 Answer 1

Reset to default 0

Answer provided by @rioV8 in comments - File Group extension allows creating groups of files that can be opened (& kept opened) simultaneously.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far