As regular readers of barnson.org know, I’m a big fan of Vim, or “vi Improved”. It’s a text editor with great keyboard shortcuts, a zillion extensions to do everything from text editing to folding to email formatting. Very convenient. I even use it to format mail messages in Microsoft Outlook, the email program I must use at work due to corporate policy.
Well, I recently changed my back-end email provider for my personal account to gmail. I’ve been mostly pleased with the transition, as I get a ton of legitimate mail and gmail makes it much easier to index.
However, there are a few things missing that I’m used to from using mutt and Cyrus Mail:
- Notification of new email arrival. Mutt would beep at me from its console window, but for gmail I’d have to look at my tab in my web browser, Firefox.
- Being able to use vim as my text editor.
- Automatically-appending witty sayings at the end of my messages. I’ve been doing this a long time using a short little bash shell script I wrote. Setting up a program to write your signature in mutt is a pretty easy thing to do.
- Automatically wrap my text at 72 characters. It’s not a huge beef, but sometimes messages get formatted very weirdly if they don’t have a good text wrap, and I want to make sure that mine are eminently readable regardless of email reader program.
Finally, I couldn’t stand it anymore, and dug around for solutions.
- For message notification, I found the Firefox Gmail Notifier. Now, Google has its own windows application to notify you when you have new gmail, but I wanted something that stayed in my browser window and would work on Linux or on Windows. Note: you also must use Mozilla Firefox, or the Mozilla browser suite, to use this tool. You should be using a Mozilla-based browser instead of spyware-infested Internet Explorer, anyway.
The solution to 2, 3, and 4 turned out to be the same thing: Using the Win32 version of Vim 6.3 (which, of course, I already had installed) combined with the Cygwin version of the “fortune” program. Since I already had Cygwin installed on my Windows box, this is a no-brainer. But from what I understand, there are native win32 versions of fortune that you can use instead.
The first thing I did was download another extension for Firefox: mozex, a Firefox plugin to allow you to run certain applications for certain types of objects on a web page. It’s pretty simple to install.
2006 update: You can download mozex for UTF-8 and compatible with Firefox 1.5 and later here! The extension is finally under development again! Yay!
Unfortunately, because the current version (as of this writing) doesn’t show up under the extensions manager in Firefox, I had to restart my browser and go to this URI: chrome://mozex/content/mozexPrefDialog.xul. This is a clickable link if you have the mozex extension installed.
Now, I have vim installed in c:\vim\, and cygwin installed in d:\cygwin\. So I wrote this shell script, which may need adaptation to your environment:
#!/usr/bin/bash # # startemail.sh # starts my vim editor with my preferred signature, among other things. echo " -- Matthew P. Barnson - - - - Thought for the moment:" >> $1 /usr/bin/fortune >>$1 /c/vim/vim63/gvim.exe -c 'set tw=72' $1
What this does is automatically append a signature to mozex’s temporary file, and then launch my editor with my preferred text wrap setting, 72 columns. I named this script “startemail.sh”, and put this script in d:\bin\, so back in my mozex configuration panel, I put this into the “Textareas” field:
d:\cygwin\bin\bash.exe /cygdrive/d/bin/startemail.sh %t
Clicked “OK”, and now when I’m editing an email in Gmail, I just right-click on the text box, go to the Mozex menu, and select “Edit TextArea”. Up pops vim with the contents of the textarea for me to edit.
There are a few other obnoxious behaviors I’d like to correct about this setup, but for now it works better than a “raw” textarea:
- Once I finish editing, save, and quit out of vim, I have to click the textarea I was working in in order for mozex to paste my work back. Not a big deal, but an extra click at the end of my work.
- Navigating a right-click menu tree to launch my editor is annoying. I need to figure out how to set up a hotkey for it instead, like “CTRL-SHIFT-E”. That would be quicker, and since one of the primary benefits of using vim is that I don’t have to use the mouse to edit text, I could keep my hand off the mouse more. For now, the annoyance factor isn’t too huge, but it’s there.
- I run two monitors: one external CRT, and my laptop LCD. Firefox has had long-standing issues with dual-monitor setups, and unfortunately has a bug here, too. You can’t get past the first cascade level of a right-click menu in Firefox on the additional monitor. So I have to keep Firefox on my LCD (primary) screen if I want to use this functionality. Vim and Cygwin have no such bugs, but it’s still one more thing to remember when I’m working, that Firefox is quirky if it’s on the second screen.
- There’s a blank bash shell open behind my vim window. Even if I attempt to background the gvim process, it’s still there. I’m certain I could get rid of it if I just used the cygwin version of vim, but the win32 version of vim has some really nice integration with the Windows Clipboard that makes life easier, and it’s not running in a dos cmd window. On the other hand, instead of using a cmd shell to run bash, I could run it via rxvt and have decent clipboard performance. The only thing that sucks there is rxvt’s startup time on windows is horrid.
- Unlike mutt, I have to configure this same setup on every computer I want to use it on. Mutt, I install it once on my mail server and I’m done. As a plus, since I chose a cross-platform solution, it can work on my Mac, PC, FreeBSD, and Linux machines. But still, it would be nice to configure it once and be done with it, you know?
That’s it for my adventure using vim as my editor for gmail. I’m actually using the same setup to write this blog entry, after having deleted the signature at the bottom.
Aww, heck, here it is anyway.
—
Matthew P. Barnson
– – – –
Thought for the moment:
In Seattle, Washington, it is illegal to carry a concealed weapon that is over six feet in length.
Oh my god thank you
this rocks. I know you didn’t write the plugin, but you brought it to my attention. Thank you very much.
The DOS version…
I’ve come up with a better solution on Windows than to start a slow Cygwin session; it saves a few seconds per message. I now only use Cygwin for one step: generating my fortune. I’ve found a few DOS fortune programs so that I wouldn’t need Cygwin for this, but since I have Cygwin installed anyway, I use it 🙂 And running cygwin’s “fortune” is nearly instantaneous.
Other bugs this fixes and/or causes:
—
Matthew P. Barnson
KDE
I’ve recently had the pleasure of using GNU/Linux as my primary workstation again (contracting rocks that way), so here’s the same setup for Firefox in KDE:
Mozex line:
And the startemail.sh script:
This, of course, assumes that “konsole” is in your $PATH. My konsole is in an unusual location (due to running Gentoo Linux), so I didn’t want to put in a full path. Same rule applies for the fortune program and vim, as well — you don’t have to specify the full path if they are in your $PATH. I also always run konsole with a dark background (for some reason, light text on a dark background is easier on my eyes), and I’ve begun specifying “set syntax=mail” so that my syntax highlighting works the way I want it to.
—
Matthew P. Barnson
Did you find a way to assign
Did you find a way to assign a key combination to the opening of the Text Area, instead of navigating the right-click menu? It’s driving me nuts too.
No
No. I dug for about six hours one night, but couldn’t find an easy way to do it. While it was worth six hours of research to me, it wasn’t worth eight. I’ve just gotten used to the right-click, mozex, edit textarea navigation thing.
—
Matthew P. Barnson
I found
an extension called Keyconfig, but couldn’t explain to it what is the code for what i’m asking. I don’t really have it clear myself. You can look at it as pressing the right mouse key, then pressing X and then E. Maybe there is a way to tell it to use this option of the extension instead of telling it what keys to press. If you feel like taking a look – that could be real nice.
When i need to move my hand to the mouse, and press all the keys, it just gets less attractive, so that i do it only for long text. This one, for example, i did not open with it. If it would be more simple i would use it a lot more often.
Found the way! (almost)
You can do somehting with the KeyConfig extension. You should bind keys to the functions mozexEditTextarea() and mozexFillTextarea(). To open your editor press the first key. When you return press the second key to get the content into the textarea. You should probably use ctrl+something as your key because normal keys should go into the textarea. But the bad news is that you still have to click once on the textarea to tell mozex what textarea you are talking about. I’ll see if I can solve this problem.
hack
I unzipped mozex.jar from the extensions directory. Then I edited mozex.js and added the line
getBrowser().addEventListener(“focus”, mozexHandleMouseDown, true);
to the mozexInit(evt) function. Then I zipped mozex.jar again and put the jar where it came from. This works for me but I’m not sure I didn’t break anything…