Friday, 13 September 2013

ColdFusion Builder to Sublime Text 2

At work the powers that be have decided we are going to pilot using Sublime Text 2.

I'm not sure what precipitated this, but I've heard a lot of people in the community bang on about it, so I've decided to give it a go. Previously we'd been using a mix of CFEclipse or ColdFusion Builder (just the freebie version). I think I was the only one who had been using CFB... no-one else had seen any merit in moving from CFE.


Anyway, our trusty system admin dude Lawrence declared that today was the day he was going to do the installs, should we want it. So I put my hand up, and am now using Sublime Text 2. Here are some notes / findings.

Configuration for CFML support

The basic ST2 install doesn't specifically support CFML, so I needed to install a plug-in for that. I googled "sublime text cfml". The first link - "SublimeText/ColdFusion · GitHub" - was the business. First things first I had to install the Package Control, which was linked to in the install docs for the CFML plugin: "Package Control". The install for this was a matter of copy and pasting some code into the Sublime Text console (View > Show Console). The code is provided on the Package Control installation page:

Simply pasting it and hitting enter effected the install. I restarted ST (dunno if I had to or not, but I did). To install the CFML package I selected Preferences > Package Control from the menu, and that yielded a warning:

So I did that. It wasn't obvious what I actually had to do in this file initially (as it's just some JSON), but this was it:

    "git_binary": "C:/Apps/Git/bin/git.exe",
        "Package Control",

(notice it also lists the packages I have installed there... I've just copied that code now, and I've installed a few packages since starting this adventure this morning).

Having done that I could then use the Preferences > Package Control option, I could select "Install Package" then key in "ColdFusion" and it offered me a package to install, which I did.

Now... this didn't work. I didn't try to work out why, because I had previously done this install process at home and taken the Git approach and that worked (and I was in a hurry... I had a bug to fix...), so I just did that. I browsed to my Packages dir (C:\Users\adam.cameron\AppData\Roaming\Sublime Text 2\Packages for me, which I found from the Preferences > Browse Packages... menu option), and cloned the Git repo (instructions on the page I linked to above). This approach did work.

I now have syntax highlighting and code assistance and all that sort of stuff available in my CFML files. ColdFusion Builder obviously has all this stuff, but I find it too slow to use on CFB: I can type things faster than it can help me. I do not find this to be the case with ST: it's very responsive, so I'll need to get used to the idea of letting it help me instead of me typing everything in.

Working out how the hell it works


First up, I needed to create some projects. I looked for a "File > New > Project" option but there wasn't one. There was a "Projects" menu, but no "New Project" option in there. I googled and discovered that to create a new project one just starts adding directories (Project > Add Folder To Project...), and that creates the project. Fair enough. One can then save the project and reuse it later.

Locating Files

Our projects have thousands of files in them, and I can't be arsed remembering where they all are. In Eclipse I use "Open Resource" heavily, so I can just type in the name of the file, and Eclipse will find it for me. I needed the equivalent in ST. Fortunately I announced on Twitter I was switching to ST, and people starting sending me usage / migration tips. Yuri Vorontsov messaged-through about CTRL-P (Goto > Anything), which is the same sort of thing as Open Resource in Eclipse. It's quite a lot more reactive than my CFB install though. It's also really cool in that as one cursors down the list of matches, it previews the contents of the file in the code window. Handy.

Above I've gone CTRL-P and searched for "junk". I've cursored down to the second item, "junk.cfm" and that's the contents of junk.cfm in the code window.

Navigating to files

Another thing that's an essential feature to me in Eclipse is the "Link with Editor" option in the Navigator tab: so that whatever file I have open in the code window, the Navigator also aligns to in its window. This is not a native feature to ST, but I was able to add the "SyncedSideBar" package, and this kinda does the same thing. It's not as good though, because whilst it expands the file tree down to the file I'm currently editing, it does not reposition the view port to show it in the navigator window. This will get annoying for me fairly quickly, I think.

Finding text in files

I had a sense of trepidation here because another essential Eclipse feature is its regex-find functionality. Fortunately ST also has this, which is good. It's also got an interesting take on the search results:

Here I've searched for "<cfassociate", and it's showing me the results as a text file in the editor window. This has the context of where the code is in each file. What's cool here is that I can then do a in-file find on that, if I need to find anything else within the context of those search results. Neat.

Finding text in open files

This is cool. ColdFusion Builder does this (but only the paid-for version!), but ST has an option to do a find-in-files, but instead of finding within the whole project, only to look in the files you've currently got open. I will use this a lot.

Finding methods in files

Within a CFC file I can go CTRL-R, and this brings up a dialog like this:

See how this lets me find a method in the file. As I type, the results filter down, and the first match is centered on the screen. Nice.


Using SHIFT-ALT-1 (-2, -3, -4) one can split the screen into multiple columns. And what's more, one can open the same file in different columns, which will be very handy.

Another nice one is  CTRL-SHIFT-D which duplicates the current selection (same as RIGHT-ALT-UP/DOWN in CFB). CTRL-SHIFT-UP/DOWN moves the current selection in that direction. Same as LEFT-ALT-UP/DOWN in ColdFusion Builder.

You might have noticed I had an MXUnit package installed... there seems to be packages for everything out there, which is gonna be nice. I've got some investigation to do.


Currently this looks like a good text editor. It makes no claim to be an IDE, but I don't need an IDE. I never use debugging in CFB - simply because to get debugging to work one has to have one's projects and websites set up in a very specific way, which I will never do as it's daft - and never use FTP or RDS or anything like that. I basically just use it as a text editor. And I think Sublime Text looks like a better text editor, so I'll try to stick with it for the time being.

I'm all ears if you want to let me know about other tricks ST has in its arsenal...

(And Matt Busche has done that very thing already... here's a Periodic Table of Sublime Text  keyboard shortcuts).