Saturday, September 29, 2007

Using Vi to edit textareas in Firefox... YES!

I have started to use TWiki at work to develop a more dynamic documentation store for my team and it beats the pants off of editing heavy MS Word docs. My problem in general with creating documents is that I spend a fair amount of my time in vi (on HPUX, Linux, Windows, everywhere; sometimes I wish I could use it everywhere) and then It happens... I switch to an application like Outlook of Word and I have to tell my brain that I am no longer in vi. What usually happens is that I end up with a lot of :w's peppered throughout my documents and other control sequences. (Accidentally hitting ESC in an email to switch to command-mode has caused me to loose more than a few messages.) So with this brand new Wiki I thought to myself can I somehow do my doc'ing via vi too? And you can!

Mozex to the rescue: Mozex is a Mozilla extension which allows you to use external applications to: edit content of textareas, view-source, mail-to, etc. I am interested in the editing of textareas with vim.
Here is how it can be done:

1) Go to the mozex site and install the latest version (development version to get Firefox 2.x support). Restart the browser.

2) Right-click on a page (anywhere) and select mozex -> Configuration.

3) Select the textarea button and then fill in the path to your favorite editor (vim) and make use of the %t to pass in the path to the temporary file. I also setup a hot-key combo as I really try to avoid using a mouse (why must you take you hands off of the keyboard?!).

4) While in your textarea press the hot-key combo and up pops vim!

Other tips: Start vim via a shell script that also accepts the %u which you can use to then set other vim preferences. I.E. If the URL is from your favorite Wiki then you could setup some custom syntax highlighting when launching vim. There are so many fun combinations, enjoy, and many thanks to the mozex team!


Utopiah said...

Just use Vimperator (cf ) to make Firefox behave "like Vim" and then type C+i inside a textarea to load its content directly within Vim,

voila !

PS : if you are interested into effective wiki edition within Firefox you could have a look at WikAlong (cf ) and my own micro-project (cf )

ab said...

I actually just installed vimperator last week and have no regrets!