Sublime Forum

Open directory from 'subl' command with directory browser visible

#1

I’ve been using BBEdit for years, and have started to use Sublime over the past year, mostly because it’s available for (and the license is good for) both macOS and Linux.

One of the most common things I need to do is, from the command line, open an editor window with the files in the current directory open in a “tree view”. I’ve always done this using the command “bbedit .”. I’m looking for the equivalent with Sublime.

So far the closest I’ve come up with is “subl -n .”, but it requires me to hit “⌘K ⌘B” to make the tree view appear on the side. Is there a command line option to make it appear automatically?

Note that I don’t want it to always appear … if I open just one file from the command line I don’t want the tree view … only if I’m opening a directory from the command line.

(Side question: why “⌘K ⌘B” anyway? It wouldn’t be so bad if it were just a single keystroke, but a sequence of keystrokes?)

0 Likes

#2

The state of the side bar is inherited from the last window that was opened; so if you create a new window while the side bar is open in the previous window, the new window will have the side bar, and vice versa.

The toggle_sidebar command is what toggles the state, so you can subl -n . --command toggle_sidebar to open a window and issue the command, which would cause it to open if it wasn’t going to be open already.

Downsides to this are that it’s longer to type (solveable with a batch file/alias) and requires that Sublime already be running somewhere or the command won’t execute.

There’s nothing special about the key binding however; you can customize it like any other key binding. For example Preferences > Key Bindings and add the following to the right hand pane:

	{ "keys": ["super+alt+k"], "command": "toggle_side_bar" },

Now the side bar will toggle with ⌘+Shift+K instead (you can of course adjust as appropriate). On Linux ⌘ is the Windows key, if your keyboard has one.

2 Likes