2011-12-07

Thunderbird and Vi Shortcuts

THE VI text editor is found on every Unix/Linux system, and it's also been ported to MS Windows. I used to have a manager who pronounced it like the verb vie. He would say, "Can't you just edit that with vie?", and we engineers would have our little chuckle. Most users call it by the individual letters: "V.I.". However, to be fair, it is just an abbreviation of visual, so vie is actually more logical.
A visual editor — what's that? Well in the olden days, the first text editors were line editors, and were based on terminals that printed on a continuous feed of paper. You worked on one line at a time. Want to edit another line? Well you type a command to switch to line 297 or whatever and start editing that one. You can experience that today by using ed or ex in Unix/Linux. (As primitive as that sounds, this was considered a huge improvement over punch cards!)  When CRT terminals became common, the visual editor was developed. It presented many lines at once (usually 24) on the screen and you could move about with keyboard commands.
Vi was an early visual editor for Unix and became a standard. It was later expanded into the Vim project (VI iMproved), which added a giant load of new features and conveniences, including color syntax highlighting, history mechanism, and improved pattern matching.
Using vi requires you to switch back and forth from command mode and insert mode. You are normally in command mode, where you type one or more characters to move the cursor or do some other task. If you type one of the insert or add commands, you are then in insert mode and anything you type becomes part of the file you are editing. Press Escape to exit insert mode. This is quite different from other text editors (like emacs) and word processing apps (like MS Word), where you are always in insert mode but you use modifier keys (Shift, Alt, Ctrl, etc.) or function keys or the mouse to execute commands.
So one of the interesting features of vi is its keyboard shortcuts for moving around the screen — j moves the cursor down one line, k moves it up, h one character to the left, l to the right. If you use the touch-typing method, you will quickly notice that those keys sit under your right fingers. (Yes, the l key moves right, not left, but the l key is on the right :-/  )
***
It turns out that Gmail's Custom Keyboard Shortcuts Lab has k and j built in as defaults for moving up and down in the message list — obviously borrowed from vi. Add in the the Auto-advance Lab and you have a very snappy webmail app with vi keyboard shortcuts.
What about Thunderbird? How to make it behave à la vi? (Not to be confused with, or prounced like, c'est la vie.) A year or two ago I looked for a solution — tried Muttator and Nostalgy add-ons. Nothing seemed to work very well.
But I was missing a lesser-known add-on called Keyconfig. You can download keyconfig.xpi from mozilla.dorando.at and install it into TB (Tools | Add-ons and then click the dropdown arrow next to Search box and choose Install Add-On from File).
After restarting TB, you will see Keyconfig in the Tools menu. You can play with that to get vi-like shortcuts. But here's a quicker way, suggested by Teleogistic. Add these lines to user.js in your TB profile directory (create user.js if not present):
user_pref("keyconfig.main.key_killThread", "][I][");
user_pref("keyconfig.main.key_markJunk", "meta shift][J][");
user_pref("keyconfig.main.key_markReadByDate", "meta shift][D][");
user_pref("keyconfig.main.key_markThreadAsRead", "meta shift][R][");
user_pref("keyconfig.main.key_newMessage2", "meta shift][N][");
user_pref("keyconfig.main.key_newMessage", "meta shift][M][");
user_pref("keyconfig.main.key_nextMsg", "][J][");
user_pref("keyconfig.main.key_previousMsg", "][K][");
user_pref("keyconfig.main.key_delete", "][D][");
user_pref("keyconfig.main.key_replyall", "shift][R][");
user_pref("keyconfig.main.key_reply", "][R][");
user_pref("keyconfig.main.key_toggleMessagePane", "][V][");
user_pref("keyconfig.main.xxx_key74_SwitchPaneFocus(event);", "][D][");
Then restart TB.
There's a whole boatload of key_ functions to play with.
One thing I noticed if you're using j and k with Gmail as the IMAP server — if you go too fast, Gmail will drop the current connection and you'll see a popup from TB asking for a new password. Don't be concerned, your password hasn't changed. Just press Escape to ditch the popup and continue as before.
But wait there's more! Another annoyance of TB is how it advances (or not) in the message list when you delete a message. If you sort with latest on top (as in Gmail), and you delete a message, TB opens the next older message, which you probably just read!
Well, sometimes ya get lucky. I finally found out there's a hidden setting to fix that. Go to Preferences | Advanced | Config Editor. Type "delete" into the Filter box. You will see a key called
mail.delete_matches_sort_order
Double-click on that so it turns bold and becomes user-set and = True. No need to restart TB.
Now it will open the next newer message after delete. 
I use both Gmail and TB (with IMAP connected to my Gmail account). Gmail can be faster for just checking mail. It is faster for searching. It's integrated into your Gmail Contacts. But TB has more predictable formatting for composing, and it's easier to insert images.

0 comments:

Post a Comment