Relative Sanity

a journal

Blaming your tools

I don't always edit code, but when I do, I edit text in Sublime Text.

Actually, that's a lie. I do always edit code.

Anyway, Sublime is full of surprises. I switched to it a few years ago after I finally got sick of TextMate not supporting split panes. I love split pane editing. Modern screens are significantly wider than they are tall, so when editing text you end up with a choice between filling the whole screen with text (leading to lines that are way too long to be readable) or keeping the window narrow, leaving a bunch of free space either side of the file.

Sometimes that's super-handy. Combined with something like BetterSnapTool, I can quickly shove my text editor into one half of the screen, and pull up a browser with, say, the code review I'm working through in the other half.

Sometimes, though, I just want to see text. Sublime has my back there too, with a full-screen mode. Just hit ⌘+ctrl+f and the editor slides over the whole screen. ⌘+⌥+2 then splits the editor view into two panes, and I can then view two files at the same time. Often I use this for keeping a test file open at the same time as editing the code it's testing. I can run the tests in Sublime too, meaning that my red-green-refactor cycle is pretty fast.

Yeah, yeah, I know. vim.

Opening files

Like most editors — and, increasingly, many productivity apps — Sublime has a Quick Open function. Hit ⌘+t (or ⌘+p if you're not a TextMate refugee) and down drops a list of all the files Sublime can see in the currently open directories. Fuzzy search is yours for the using, here — start mashing keys and Sublime usually figures out what you mean. It's smart enough to favour recently opened files too.

But wait, how do I open directories in Sublime? For that, I use the command line tool, subl. This comes bundled with Sublime, and if you use Homebrew in concert with Homebrew Cask to manage your software, it all gets set up with a simple:

% brew cask install sublime-text3

I can now say % subl . in the console to open the current directory in Sublime.


But what if I want to open multiple directories? For example, I might be in a project where I really only care about a templates directory and a css directory. I can say:

% subl public/assets/css system/templates

and only those directories will be opened in Sublime.

Now, let's say I'm editing templates, so I drop this in the terminal:

% subl system/templates

I happily work away, then realise that I need access to the project's javascript as well. "No problem", I think:

% subl public/assets/js

but nooooooooo! This pops open another Sublime editing window. If I'm running fullscreen, I'm now flipping back and forth between screens. This is no good. I wanted to add the directory to the currently open Sublime window, not open a completely separate one.

Old dog. Moderately new trick

I've known for a while about the Project -> Add Folder to Project… menu item in Sublime, but I never seem to use it. I don't think about "Which directories are open in Sublime" as a Sublime-managed thing — it's a terminal thing, in my mind. I use subl to send stuff to Sublime for editing, so flipping to Sublime text first feels counterintuitive.

Why I'd never tried this before today is beyond me, but I'm glad I did:

% subl --help 
Usage: subl [arguments] [files]         edit the given files
   or: subl [arguments] [directories]   open the given directories

  -a or --add:         Add folders to the current window


% subl -a public/assets/js

and I'm done.

Seriously, always read the damn manual.