open_file command only expands a few variables (
$platform; possibly others but those are the only ones I’m aware of off the top of my head). So directly, that’s not something that you can do.
However it’s simple to make a plugin that adds that sort of functionality, such as the one below (see this video if you’re not sure how to use plugins):
Drop in replacement for the open_file command that expands
environment variables as well as standard Sublime variables in all
def run(self, **kwargs):
# Create a set of variables based on the current process
# environment and the standard Sublime variables
variables = dict(os.environ)
# Expand all variables and execute the base command with them
kwargs = sublime.expand_variables(kwargs, variables)
This creates a drop-in replacement for the
open_file command named
open_file_env that performs the same action as the built in command but also will expand environment variables as well (plus any variable that you can use in a
In use, you’d do something like the following, presuming an environment variable named
MY_LIBRARY_PATH was set to the appropriate location:
The syntax will always be to use
$ for the environment variable (even on Windows, where that’s not usually how variables are expanded), and the names of the variables are based on the names that come from the process environment, so the case depends on how you set up the variable.
Note also that Sublime doesn’t see changes made to the environment while it’s running, so adding or changes variables requires you to restart it. Similarly on Linux the process environment is inherited from the parent process, which might be your window manager. In such a case you may also need to log out and in again to propagate the change (or just start Sublime manually from a terminal that has the new environment set).