Monday, January 19, 2009

Vi (and Emacs) key bindings in the Abiword word processor

As a long time occasional user of the programmer's editor, Vi, I have found its modal nature (you edit using two (actually, three) modes: command mode and input mode) very convenient, once I become (re)accommodated to it. I wondered whether any word processors supported a Vi-compatible input mode.

Some googling revealed that the open source word processor, Abiword, has a limited Vi input mode. However, the instructions for enabling it were not clear; I found partial information on several websites, and I also found several comments from frustrated users who could not get the instructions to work for them.

To enable the Vi input mode, one needs to edit their AbiWord installation's file "AbiWord.Profile". However, the exact editing that will work is quite particular. In experimenting, it is apparent to me that AbiWord.Profile is rewritten each time AbiWord exits. Edits to the file that do not fit AbiWord's expectations are not written out when this rewriting occurs. In one set of comments, users indicated that when they deleted AbiWord.Profile, causing AbiWord to generate a fresh copy upon startup, their edits and the desired effects of those edits then worked as expected and persisted. I've not tried doing this, yet, and so cannot speak to it.

I did manage to get the Vi input mode working for myself. I am using Windows XP. Under XP, the file "AbiWord.Profile" is located under "\Documents and Settings\[user id]\AbiSuite" where [user id] is the name of the Windows XP account that you are using.

Within AbiWord.Profile, make the following changes:

Leave the element "Select" alone; don't change it. It will look more or less like this:


<Select
scheme="_custom_"
autosaveprefs="1"
useenvlocale="1"
/>


Note that if you attempt to comment out element "Select" (to leave it in the file for future reference) while entering your own version of the element, the commented out version will be removed when AbiWord next rewrites the file.

Next, in the element "Scheme" as shown below:


<Scheme
name="_custom_"
ZoomPercentage="144"
/>


Add the attribute KeyBindingsCycle="1". The revised element will look like this:

<Scheme
name="_custom_"
ZoomPercentage="144"
KeyBindingsCycle="1"
/>


Save the file. When you next run AbiWord, the key "F12" will cycle between the three available input modes: "default", "viEdit", and "emacs". If you exit AbiWord while in "viEdit" or "emacs" modes, AbiWord.Profile will be rewritten to include the mode you were in at the time you exited. For example, if you exit while in viEdit, element "Scheme" will be updated to include attribute KeyBindings="viEdit", like so:

<Scheme
name="_custom_"
KeyBindings="viEdit"
ZoomPercentage="144"
KeyBindingsCycle="1"
/>
This information is current for AbiWord version 2.6.6 for Windows XP (installation file "abiword-setup-2.6.6.exe").

Here are some of the resources I referenced while figuring this out:

http://linuxmafia.com/faq/Apps/abiword-vi-mode.html

http://www.jukie.net/~bart/blog/tag/vi

http://www.abiword.org/mailinglists/abiword-user/2003/Mar/0023.html

http://www.abisource.com/wiki/FaqEditorBindings

http://www.abisource.com/wiki/KeyBindings

http://www.abisource.com/support/faq/

1 comment:

  1. In Preferences of Abiword is a checkbox, which allows to allow mode switching. It worked for me.

    Anyway, the vi-mode seems a bit slow, AbiWord did not catch some of my keystrokes, also things like "dt." - delete till dot, did not work, so it looks like rather poor implementation.

    ReplyDelete