Xaprb

Stay curious!

Archive for the ‘Desktop’ Category

Lessons learned from the Sublime Text editor

with 11 comments

Terminal-based, keystroke-driven editors are enormously powerful, and I still haven’t seen anything more powerful than Vim. I’m a longtime Vim user, and although I’m not the world’s foremost jaw-dropping expert on Vim, I would call myself an advanced power user at the very least, and probably a true expert. Still, I have maintained a relationship with GUI text editors over the years, too. An editor that has an insertion point for a cursor, and “native” mouse interaction, has an appeal I’ve never quite shaken. I’ve used (and been highly productive with) Kate, GEdit, Notepad++, Visual Studio, and many others. I have purchased licenses for Textpad, Textmate, and most recently Sublime Text 2.

Sublime Text is a very nice editor. I’ve chosen it for my recent Go programming because of the GoSublime integration, which uses gocode (which also works for Vim, by the way) to provide IDE-like autocomplete and other helpful functionality, like incremental syntax checking and running gofmt on save. Sublime Text also has a limited Vim emulation mode, which lets me drop into Vim command mode for some mouseless productivity.

Keep in mind that I think Sublime is great, and well worth the license fee. That said, I find its advocates a bit wide-eyed and breathless in their enthusiasm. I keep thinking, Have they never used a decent editor before? Take the “multiple selection” feature. You can select something, such as a variable name, then press Control-D repeatedly and select other occurrences of the same text. Then you can type, and all of the occurrences change simultaneously. Revolutionary! Any praise about multiple selections is an understatement!

Really? You’ve been able to do that with just as few, or even fewer, keystrokes in Vi or Vim forever:

:%s/oldtext/newtext/gc

All you have to do is press a key for every occurrence. If you want to change them all without confirmation, leave off the trailing ‘c’ command to the regular expression. This is basic, not a power-user feature. It’s Unix regex 101 for any number of tools — nothing new to learn here.

Similarly, a number of other purportedly “new” features in Sublime Text 2 are decades old, well-worn and loved in many other text editors. I’ll admit that most of the mouse-based, cursor-insertion-point, GUI text editors don’t offer these types of features in any usable or convenient way; they just seem to lend themselves much better to terminal-based editors like Vim and Emacs. (Example: passing selected text through a shell command and reinserting it into the file.)

In fact, many of these older text editors offer way more functionality than Sublime Text. It doesn’t even come close. The find-and-replace in Vim, for example, is way better than the dialog-based functionality in Sublime Text, or nearly any GUI editor for that matter. Not to mention the documentation; Vim’s documentation and help system is breathtaking, but Sublime Text’s is… uninspired at best. You can compare terminal-based text editors to Sublime Text on a bunch of dimensions and it comes up way, way short. Again, this is just some rambling thoughts — I repeat, I bought the license. And I’m sure Sublime Text is going to continue improving rapidly, as it has been the whole time I’ve been aware of it.

And now we come to my point: it appears to me, from the enthusiastic response to Sublime Text, that a large proportion of the developer population either uses a weak-sauce text editor or is utterly untrained on using a powerful one. How else can we explain the enthusiasm? I honestly can’t think of anything. And this is a really saddening thought, because it means that thousands of programmers have completely neglected one of the most important things they could do: become truly proficient, if not expert, with their text editor. The text editor is to the programmer as the wrench is to the mechanic, as the compass is to the navigator, as the shoe is to the runner. It is arguably the single most important tool you’ll use as a programmer.

There’s just no excuse. If you aren’t using a powerful text editor (and I would count Sublime Text as one), get one. And if you aren’t at least an advanced user of that editor, get a move on it. I’m not the first to say this, but I can’t remember or locate the quotation about this topic that I’m trying to recall. Maybe someone can help out in the comments.

What’s your favorite text editor? What’s your favorite resource for becoming an amazing wizard with it, so that you regularly do the kinds of tricks that make your friends say “hey, what editor is that?”

Written by Xaprb

November 20th, 2012 at 9:14 pm

Posted in Coding,Desktop,Tools

Making auto-resetting VirtualBox machines

with one comment

I don’t know if I’ve said this before, but I absolutely love VirtualBox. It makes it so easy to run Windows in the cases where I have to for a client’s silly Windows-only VPN software or something like that. Windows runs better inside VirtualBox than it does on bare hardware.

One of the tricks I use constantly is to set up a bunch of VirtualBox instances with a common (shared) base disk image. You can do this by creating a machine, installing your operating system on it, then throwing away the machine and keeping the resulting disk image. You can then keep this image registered inside VirtualBox, but detached from any actual machines. Then set it immutable so it never changes again:

VBoxManage modifyhd HardDisks/Windows_XP.vdi --type immutable

Substitute the name of your actual disk image file. Now you have a freshly installed Windows image on that file, which can serve as the base for lots and lots of machines. I have one set up with Service Pack 3, all the usual annoyances disabled, etc etc.

Now here comes the magic: you can create special-purpose machines that always revert to the fresh image when you boot them up. Let’s say I want an image with an annoying VPN installed. I will create a new machine, call it Windows_XP_VPN, and select the Windows_XP.vdi file as its disk image. After selecting this disk image, I juts go through all the rest of the settings, finish the wizard, and I have my machine. I boot it up, make some changes, and when I shut it down, all the changes it’s made are stored in a differencing disk image file. It doesn’t touch the base image file; any modifications are made to a copy-on-write image file.

The special characteristic of this differencing image file is that it resets on boot. If I shut down the machine and look at the image files, I’ll see one that’s oh, maybe a couple hundred megabytes. I can have lots of these images sharing the same base image file that usually ends up being multiple gigabytes, so sharing the base image file is a great way to save on disk space. But what happens when I restart this machine, is that the differencing file gets emptied first. If I boot up, save a file on the desktop, and restart, the file is gone. I’m back to the fresh image.

So this isn’t the full solution, actually, because the nasty VPN software I installed isn’t there after restart. I want it to persist. How can I do this? It’s actually pretty simple. I’ll just set the differencing image not to reset at boot:

VBoxManage modifyhd Machines/Windows_XP_VPN/Snapshots/[image file name] --autoreset false

Now this machine will store its state across reboots. However, I actually like Windows machines to reset at boot. If I don’t have them doing that, they eventually fill up with garbage. I want a clean image, with the VPN installed, and every time I start the machine I want that minty-fresh just-installed nasty VPN feeling. How can I do this? It turns out this is also not hard. Instead of turning off autoreset on the image, I just take a snapshot after shutting down. Only the most recent state (which is stored in a differencing image file) will be configured as auto-reset. Snapshots are stored in a snapshot image file that doesn’t get reset. Whatever changes I made before I took a snapshot, are persisted across reboots.

To illustrate this, let’s say I start a fresh machine from my base disk image. Then I install VPN on that, and shut down. If I reboot now, I lose my VPN. But if I take a snapshot, and call it “VPN installed” or something like that, when I restart my VPN is still there. Now I’ll make a folder and put it on the desktop, and reboot again. Presto — the folder is gone, but the VPN is still there.

It’s magic, and it’s the nicest thing ever, especially for Windows. No worries about viruses, no problems installing some junk spyware that some customer thinks is a good screen-sharing tool, whatever. I can trash the machine, shut it down, and when I reboot it, it’s spiffy clean.

And this brings me back to my original point: I love VirtualBox.

Written by Xaprb

August 31st, 2011 at 9:21 am

Posted in Desktop

Tagged with ,

Easy on the eyes: the solarized color theme

with 2 comments

I recently set up the solarized color theme for my terminal emulator. I’ve been meaning to do this for a while, but procrastinated. However, I finally got really frustrated with the colors I get from “ls” sometimes — I use a dark terminal with light fonts, and the directory listings in particular can become invisible, with dark blue on black.

Solarized is much improved. All of the colors work well together and are easy on the eyes. What a relief! Recommended for programmers and system administrators. There are plugins or configuration files for a huge variety of programming environments and programs, including Vim of course.

I use XFCE’s terminal, and I found that there was no terminal configuration file for it in the download. But I found a workaround: just append the colors listed in this file to the end of $HOME/.config/Terminal/terminalrc.

Written by Xaprb

July 28th, 2011 at 8:16 am

Posted in Desktop,GNU/Linux,Sys Admin

Tagged with , ,