Tom
Tom

Reputation: 641

Sorting files in VS Code Explorer

I'm using VS Code 1.25.1 on Win10. When I open the Explorer icon and look at a list of files in a folder, it shows the files listed alphabetically. I want to sort them by date modified, but I don't see any options to sort by other fields. Are there keyboard shortcuts? Any other options? Thanks.

Upvotes: 64

Views: 52963

Answers (4)

Veve
Veve

Reputation: 6758

  1. Install jq if you don't already have it
  2. Save your workspace somewhere like ~/your.code-workspace for example
  3. Execute jq '.folders |= sort_by(.path)' ~/your.code-workspace > ~/tmp.$$.json && mv ~/tmp.$$.json ~/your.code-workspace
  4. Profit

It uses the |= "update" operator to sort folders, then puts the result in a temporary file ($$ generate a random number to avoid collision) and overrides the original workspace file with this file.

Upvotes: 0

Jared Selcoe
Jared Selcoe

Reputation: 71

So interestingly the Sort Order setting only seems to impact folders and files within the top-level workspace folders, if those top-level folders were added via the Add folder to workspace option.

For ex I had

Workspace
- ProjectA
- ProjectB
- ProjectC

Then I added another folder to the workspace, and it appeared at the bottom of the list. Because it was a top-level folder the Sort Order setting would not impact its order in the list. The Sort Order would only impact the files and folders within each of those ProjectX folders.

To fix this I directly edited the workspace file. To do so, open it with a text editor other than VSCode, and change the order of listed files.

For ex, mine looked like:

{
  "folders": [
    {
      "path": "../../Desktop/ProjectA"
    },
    {
      "path": "../../Desktop/ProjectB"
    },
    {
      "path": "../../Desktop/ProjectC"
    },
    {
      "path": "../../Desktop/NewProject"
    }
  ],
  "settings": {}
}

and all I had to do was change it to:

{
  "folders": [
    {
      "path": "../../Desktop/NewProject"
    },
    {
      "path": "../../Desktop/ProjectA"
    },
    {
      "path": "../../Desktop/ProjectB"
    },
    {
      "path": "../../Desktop/ProjectC"
    }
  ],
  "settings": {}
}

Upvotes: 7

jabacchetta
jabacchetta

Reputation: 50048

  1. Open user settings (Mac: cmd+, Windows/Linux: ctrl+,).
  2. If you want this new sort order to apply to all VSCode projects, continue to step three. If you want it to apply only to the currently opened folder/workspace, first click on the "Workspace" tab that's directly below the settings search bar, then continue to step three.
  3. Using the settings search bar, search for the following setting ID: explorer.sortOrder.
  4. Click the dropdown for that setting and select your preferred sort order (in your case, modified).
  5. If you'd like to quickly toggle this setting between different values (via a keyboard shortcut), use the Settings Cycler extension.

Upvotes: 69

Jesus Iniesta
Jesus Iniesta

Reputation: 12489

A more user friendly approach can be:

  1. Open the workspace settings:

    Ctrl+Shift+p

    And open: Preferences: Open Workspace Settings.

  2. Browse to Features > Explorer using the sidebar.

    Open worlspace settings

  3. Use the Sort Order option to customise sorting.

    Select Sort Order in settings

Upvotes: 33

Related Questions