jEdit is Genius (Soft Tabs done Right)

Problem: By default, I like to use a rather nonstandard tab width of six (6) characters. In and of itself, this is not a problem, except that I also tend to align otherwise off-by-one-or-two sections of code with a space or three. This results in code that looks a bit weird when viewed with an editor that thinks tabs should be anything but six characters.

Now, there is a pretty good solution to this problem, which is to have your editor insert your preferred number of spaces when you press the tab key; since everyone views spaces the same way, this results in files that are guaranteed to look the same in any editor using a fixed-width font. The only problem here is that when you press the backspace key, only one space is deleted, so pressing <Tab><Backspace> results in a different file depending on whether so-called “soft tabs” are enabled.

Aha! But, as the title implies, the ever-so-handy jEdit comes to the rescue.

Go to Global Options -> Shortcuts. Select “Macros”, scroll down to “Greedy Backspace”, and set BACK_SPACE (or whatever key you want) as the primary shortcut. Now, whenever the caret is preceded by *some multiple* of six (or whatever) space characters, one tab’s-width of space characters will be deleted. Thus, pressing <tab><tab><backspace><backspace> on a blank line results in a blank line. Pressing <tab><space><backspace>, however, results in a tab’s-width of spaces, since only the last space was deleted.

Similar overrides are available for the left/right directional arrow keys.

All Hail Ollie Rutherford, author of Greedy_Backspace.bsh

– edit: Dammit, I *have* to get WP to stop stripping out tags it doesn’t recognize.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s