If you're a regular Lifehacker reader and Linux user, you probably have a hole in your productive little heart where a great text substitution app should be. Our own Texter makes repetitive phrases a snap to call up in Windows, TextExpander gives Mac users loads of quick-text options, and you've read all about how you can save time with text substitution (or hit the play button above to see it in action). Say goodbye to unrequited speedy-text love with Snippits, a free, open source utility that can insert text, activate program shortcuts, correct spelling, and even run bits of code, all at the touch of one button. Here's a quick start guide to installing and customizing Snippits to start saving time and keystrokes in Linux.

I'll be using Ubuntu 7.10 to walk through installation and setup. Snippits, however, can work from any system that supports the Ruby programming platform, and finding equivalents to the packages listed below shouldn't be too difficult in most Linux distros. I'll also note here that Snippits is still in development, under the steady hand of Ben Kudria, and might produce the occasional bug or oddity. Overall, though, I've found it to be a pretty helpful tool in a working Linux desktop.

Installation

We're going to hit the command line pretty hard here, but it's almost entirely a cut-and-paste affair, so no need to get scared off. The first thing we'll need to do is install Snippits' prerequisite packages. Open a terminal and enter the following:

Once that's completed, enter the next two commands one at a time, answering "Yes" to any prompts it brings up:

sudo gem install raspell

sudo gem install snippits

UPDATE: I've removed a suggestion and some code that modifies a system file. Installing Snippits using this guide should already take care of the suggested change, according to the program's creator.

Next up, we'll make the directory in which we'll stash our custom text strings. In a terminal or in your file explorer, create the ".snippits" folder in your home directory; the command line code is:

sudo mkdir ~/.snippits

One more task before we can really get started. Create a new text file in that .snippits directory called "do" (as in sudo gedit ~/.snippits/do) and paste only the following line in it before closing and saving (and trust me, this will make sense soon):

{c}{s}{left}{c}{s}{c}x{c}{paste}

Set your shortcut

Snippits doesn't have the ability to trigger text strings from hitting the space bar or Enter key (yet), so you'll have to assign its function to a key you don't use often. I gave over the Pause/Break key to Snippits, since I almost never use it elsewhere, but you'll likely have your own preferred key to assign.

If you're running a GNOME desktop with Compiz, make sure you have the advanced configuration settings tool installed:

sudo apt-get install compizconfig-settings-manager

Head to your System menu, then Preferences->Advanced Desktop Effects Settings. Select the "General Options" button, and then the "Commands" tab. Enter "ks do" on an empty command line (probably 0) and then select the "Actions" tab at the top. Unfold the "Commands" list there, double-click the "Key" field next to the command you selected before, and enter the key you want to activate your text replacements.

It's more straightforward in a KDE desktop. From the Settings menu, select Regional & Accessibility->Keyboard Shortcuts->Input Actions, then assign "ks do" to a key.

Basic triggers

Now comes the fun part. There's no GUI for creating Snippits' text triggers, but it's a simple text-based process. To make the simplest kind of trigger, create a new text file in your ".snippits" folder and name it what you want to type to activate it. For example, I'll create a file named webpic—no .txt or any other extension—and put the HTML code for placing an image in it:

Save and close that file. Now, whenever I type "webpic" into almost any application (any application that supports basic copy & paste, that is) and hit my shortcut key, it replaces that trigger word with the full HTML string. Nifty! I have to note, however, that Snippits eliminates any text you might have in your system clipboard when it does its thing, but tools like Klipper/Glipper, or GNOME's built-in clipboard-bypassing copy/paste can alleviate that problem.

Tricky triggers

But let's dig deeper. This time, I want my cursor to end up inside the string instead of having dummy text. So I open the trigger file and insert a "{cursor}" where I want it to end up, and that's that. Snippits has a slew of bracketed commands that you can use to basically perform anything your keyboard can do. Getting to the preferences menu in my Firefox window, for example, normally takes heading to a small "Menu" button in the top-right corner (because I'm addicted to the Tiny Menu extension), heading to "Edit" and then "Preferences."

Or, I could create a file called "prefs" in my Snippits folder and put this in it:

{alt}m{alt}en

The "{alt}" code is a switch, like holding down the key, so I use it a second time to "release" it, then type the letters I'd normally hit (but can never remember) to get to what I need. Now I simply type "prefs" into the address bar (or anywhere) and hit my Pause shortcut, and there I am.

A full list of read-able codes is available at Snippits' ReadMe page. Here are a few more tips on getting the most out of Snippits:

Word spell-checking: If you hit your Snippits key after typing a word that's not one of your Snippits files, it runs the word through your built-in Aspell dictionary and corrects it if necessary.

Useful examples: Snippits' author threw a few examples of useful Snippits in with the program, although you'll have to find and move them to get access. In Ubuntu 7.10, I found them in /var/lib/gems/1.8/gems/snippits-0.5.1-/examples (whew!) and copied them to my .snippits directory. That gives you access to utilities like "time" and "date," which print out exactly what you'd think, as well as others that might inspire you to get crafty with your own Snippits

Key-specific triggers: If you find yourself accidentally firing your substitutions with certain words, you can set specific Snippits to activate with a different key. Simply head back to your system's shortcuts menu and add "ks [Snippits name]" to another key combo. The program's author, for instance, pastes his email address only when he presses a Win key + I, E combination.

Now you're all set up to make the most of your text entry in nearly any Linux application. I'd love to hear if any of our intrepid readers come up with some ultra-useful shortcuts, with code or without, that make life easier, so feel free to share your discoveries in the comments.

Kevin Purdy, associate editor at Lifehacker, can finally, finally say goodbye to manually typing out his Lifehacker post code on all his systems, thanks to Snippits. His weekly feature, Open Sourcery, appears every Friday on Lifehacker.