Scorb
Scorb

Reputation: 1850

Sublime Text open open relative to project directoy

I have a command mapped to ahotkey in sublime to open the user directory...

{ "keys": ["ctrl+alt+u"], "command": "open_dir", "args": {"dir": "$packages/User/"} },

How can I have a similar command that opens a directory two levels up from the project directory?

Upvotes: 0

Views: 34

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

The path variable $project_path expands out to the location of the current sublime-project file (which is specific to the current window) in the same way that $packages expands to the location of the Packages folder.

So, the following will open the directory two levels above the location of the current sublime-project file:

{
    "keys": ["ctrl+alt+u"],
    "command": "open_dir",
    "args": {"dir": "$project_path/../../"}
},

Sometimes people store their sublime-project files in locations other than the locations where their project files are actually stored (e.g. to centralize them all in one location or to remove clutter).

In that case, if you want the binding to open two levels above where the contents of the project are, you can use the $folder variable, which expands out to the location of the first folder that's open in the project (or window).

{
    "keys": ["ctrl+alt+u"],
    "command": "open_dir",
    "args": {"dir": "$folder/../../"}
},

Upvotes: 2

Related Questions