VBacs (Visual Basic Emacs)

by Christopher Rath & John Cooper

VBacs Key Bindings

I am a long-time Emacs user—generally XEmacs, but GNU Emacs, µEmacs, Microemacs, Golem, and other variants too—and am very frustrated by Microsoft’s default MS Word user interface.  So, I created some Visual Basic for Applications (VBA) macros which remap my keyboard to provide a basic set of Emacs key bindings.  Download the following link and follow the instructions enclosed therein (release notes and the change log appear at the bottom of this webpage).  If you're looking for an older release of VBacs, see the bottom of this webpage.

For Word 2007 and higher: VBacs_3.06.zip — The macros are copyrighted, but are distributed under the GNU Lesser Public License.

For Word 2003 and lower: VBacs_2.17.zip — The macros are copyrighted, but are distributed under the GNU Lesser Public License.

Thanks to Word97 Annoyances, by Woody Leonhard, Lee Hudspeth & T. J. Lee; the book that showed me how to start the process of constructing this macro set.

Regarding Outlook

Because Outlook 2007 no longer inherits Word 2007 customisations, starting in Office 2007 VBacs does not provide any Emacs bindings in Outlook.  To that end, John Cooper has taken the AutoHotKey product (GPLed) and put together an AutoHotKey script to provide Emacs key bindings in Outlook 2007. His script can be found in AutoHotKey's “Scripts & Functions” forum; he's entitled his script "AutoMacs".

Other Customizations to MSWord

Making MSWord look a little like Emacs is only one part of the changes I make to MSWord, I also make a few other changes.  I have captured these customizations in a “Personal.dot” template which I also place in MSWord’s Startup folder.  My current version of this package can be found at the following link (note that much less release discipline has been applied to this package, compared with VBacs.dot):

For Word 2007 and higher: Personal_3.03.zip — These macros are copyrighted but distributed under the GNU Lesser Public License.

For Word 2003 and lower: Personal_1.20.zip — These macros are copyrighted but distributed under the GNU Lesser Public License.

Personal.dot release notes.

For other VBA code I've authored, see my Visual Basic for Applications (VBA) Resources.


VBacs (Visual Basic Emacs)
Version 3.06 — 2010-10-18

Release Info.

' VBacs - VBA to create Emacs short-cut keys in MS Word.
' Authors: Christopher Rath <>
'        & John Cooper <>
' Date: 2013-10-18
' Version: 3.06
' Archived at: http://www.rath.ca/Misc/VBacs/
' Copyright (c) 1998-2013 Christopher Rath
' Distributed under the GNU Lesser General Public License v2.1
'   (see the LGPL_License VBA module for the license text)
' Warranty: None, see the license.

Contributors

I would like to thank the following individuals for their code and idea contributions to VBacs:

Compatibility

MS Office 2003 on Windows XP is my primary development, test, & personal use environment for VBacs; however, here's what I know about VBacs compatibility with other environments.

Environment Commentary
MS Office on MS Windows VBacs version 2.xx has been tested with MS Office 2003, users have also reported success running it with MS Office 97, MS Office 2000, MS Office XP, and MS Office 2007 (except for Outlook 2007).

VBacs version 3.xx is only compatible with MS Office 2007 and newer.
MS Word on MacOS I have performed very limited testing of VBacs version 2.09 on MS Word 2004 running under Mac OS X v10.4 Tiger.  What I found in that testing is that the default installation of MS Word does not define a valid path to the Startup folder (open the Preferences panel & go to the File Locations section).  To allow VBacs to run ensure that you have updated the Startup path to point to a folder to which your userid has write permission.  For some strange reason, the  System.PrivateProfileString VBA function does not properly resolve filename paths and so VBacs.ini is created with a name of startup\VBacs.ini.  While this doesn't seem to impede VBacs operation, it is an annoyance.

Bugs

MS Word’s VBA has an inherent design limitation whereby MS Word does not leave ExtendMode when a VBA function exits. This means that in implementing VBacs we have not been able to make use of MS Word’s ExtendMode in VBacs’ insertion point movement functions. We have implemented an internal ExtendMode that is used by the VBacs functions, but this sometimes means that ExtendMode will be active in circumstances where Emacs or MS Word would have reset ExtendMode. The best example of this is where you set the mark, move the cursor, and then begin to type: everything works as expected until you use one of the VBacs cursor movement functions, when it becomes evident that the internal ExtendMode is still active (this occurs because normal typing does not invoke a VBacs function and so the internal ExtendMode doesn’t get reset). In these situations, simply press Ctrl+G to cancel ExtendMode.

There is a nagging EasyFind interaction problem with Windows 7 (64bit) that I haven’t been able to eradicate: when a [Ctrl] and/or [Alt] key sequence is press (with or without [Shift]), while the initial key sequence is correctly processed, subsequent key presses that occur before the [Ctrl] and/or [Alt] keys are released do not work correctly—the key press is interpreted without the modifier key(s).

Installation Instructions

To install the VBacs macros into your copy of MS Word:

  1. Check to see if any other macros (possibly an earlier version of VBacs) need to be removed.  This can be done by opening the “Templates and Add-Ins…” panel (OfficeàWord OptionsàAdd-InsàWord Add-insà[Go]).
  2. Consider whether you need to remove any existing custom key bindings before installing VBacs.dot.  If you do, this is done by going to OfficeàWord OptionsàCustomizeà[Customize] and with Normal.dot appearing in the “Save changes in:” field press the [Reset All…] button.
  3. Copy this file into your MS Word Startup folder. If you’re not sure where this is, check the location by going to OfficeàWord Options]àAdvancedàGeneralà[File Locations] and checking the “Startup” entry.  I strongly recommend actually double-checking the Startup folder location.  Please be aware that on some versions of Windows the Startup folder is hidden; you can view hidden folders by opening Explorer and then checking the “Show hidden files and folders” option on the ToolsàFolder OptionsàView panel.
  4. 4. Check your MS Word security options to ensure that the signed macros will run (Officeà[Word Options]àTrust Centerà[Trust Center Settings…]àMacro SettingsàDisable all macros except digitally signed macros)
  5. Close all open MS Word documents and exit the program (i.e., choose FileàExit in all documents and MS Word windows; this will also require you to exit and logoff of MS Outlook).
  6. Restart MS Word.
  7. Read the “Configuration Instructions” section, below, and decide if you need to edit VBacs.ini.

Uninstall Instructions

Permanent removal:

  1. Exit MS Word, and any application which runs MS Word as a child process (e.g., MS Outlook).
  2. Remove VBacs.dot from your MS Word Startup folder.
  3. Restart MS Word and you should find that VBacs is no longer active.

Temporary removal:

  1. Open the “Templates and Add-Ins…” panel (OfficeàWord OptionsàAdd-InsàWord Add-insà[Go]).
  2. Uncheck the VBacs entry.

Configuration Instructions

When VBacs is installed, the following options panel is available from MS Word’s Tools menu: ToolsàVBacs options….

Picture of VBacs Options panel.

The first time MS Word is run following the installation of VBacs, a configuration file, VBacs.ini, is created in your MS Word Startup folder. Edit VBacs.ini using the VBacs option panel (see above) or Notepad.

For those who prefer to manually edit the file, the VBacs.ini variables are as follows:

GosmacsTransposeChars — determines whether Ctrl+T transposes characters as Emacs would (where the characters on either side of the cursor are transposed), or whether it will transpose the two characters immediately preceding the cursor. The default value for this variable is “False”; which enables traditional Emacs behaviour. Use a value of “True” to enable the non-Emacs behaviour.

KillWholeLine — determines whether Ctrl+K kills the paragraph marker when it terminates the end of the line being killed. The default value is “False”; which will not include the paragraph marker in the killed text. Use a value of “True” to include the paragraph marker in the killed text. Note, a line containing only a paragraph mark is always killed, regardless of the setting of this variable.

CollapseSelectionOnCopy —determines what to do with the active selection region when it is copied (for example, using Alt+W). A value of “True” collapses the selection on copy; just as Emacs does. A value of “False” does not collapse the selection; which is how MS Word behaves. The default value is “True”.

UseEasyFind — determines whether search-forward/search-backward (Ctrl+S & Ctrl+R) invoke the EasyFind search panel or use the older VBacs search mechanism. Note, the regular expression search commands are not affected by this option; since EasyFind does not support regular expression searching at this time.

Usage

Once the VBacs template is installed, the following shortcuts are available:

Standard Emacs Bindings

Action Key Binding

Line Up

Ctrl+P
Up

Line Down

Ctrl+N
Down

End of Line

Ctrl+E
End

Start of Line

Ctrl+A
Home

Start of Buffer

Shift+Alt+<
Ctrl+Home

End of Buffer

Shift+Alt+>
Ctrl+End

Character Forward

Ctrl+F
Right

Character Backward

Ctrl+B
Left

Word Forward

Alt+F
Ctrl+Right

Word Backward

Alt+B
Ctrl+Left

Universal Argument (see note, below) Ctrl+U
Sentence Forward Alt+E
Sentence Backward Alt+A

Paragraph Up

Shift+Alt+{
Ctrl+Up
Paragraph Down Shift+Alt+}
Ctrl+Down

Page Down

Ctrl+V
Page Down

Page Up

Alt+V
Page Up

Go To Previous Page Ctrl+X [
Go To Next Page Ctrl+X ]
Recenter Ctrl+L
Goto Line Alt+G

Search

Ctrl+S
Ctrl+R

Regexp Search Alt+Ctrl+S
Alt+Ctrl+R
Replace Alt+%
Ctrl+Alt+%
Set Mark Ctrl+Space
Ctrl+@

Cut Selection

Ctrl+W

Paste Selection

Ctrl+Y

Copy Selection

Alt+W

Select Whole Buffer Ctrl+X H

Delete Word Forward

Alt+D

Word Delete Backward

Alt+Backspace

Delete

Ctrl+D

Delete to End of Line

Ctrl+K

Edit Undo

Shift+Ctrl+-
Ctrl+/
Ctrl+X U

Cancel

Ctrl+G

Tab

Ctrl+I

Save File

Ctrl+X S

Close File

Ctrl+X K

Exit MS Word

Ctrl+X C

Open File

Ctrl+X F

Undo

See Edit Undo

Exchange Point And Mark Ctrl+X X

Open Line Above

Ctrl+O

Capitalize Word

Alt+C

Upshift Word

Alt+U

Downshift Word

Alt+L

Delete Window

Crtl+X 0

Close Other Windows

Crtl+X 1

Split Window Vertically

Ctrl+X 2

Go To Other Window

Ctrl+X O

Switch To Buffer Ctrl+X B
Iconify MS Word Ctrl+Z
Centre Paragraph Alt+S
Transpose Characters Ctrl+T
Transpose Words Alt+T

Handy Non-Emacs Bindings

Action Key Binding

Paste Plain (see note, below)

Ctrl+Shift+Y

Access To MS Word Bindings
(bindings over-ridden by VBacs)

Action Key Binding

Select All

Ctrl+Q A

Bold

Ctrl+Q B

Edit Find Ctrl+Q F

Italic

Ctrl+Q I

Insert Hyperlink Ctrl+Q K
New Blank Document Ctrl+Q N

Print

Ctrl+Q P

Hanging Indent Ctrl+Q T
Underline Ctrl+Q U

Tab (in a table)

Ctrl+Q [Tab]

ResetChar Ctrl+Q [Space]

Notes:

EasyFind Notes

EasyFind is a find panel tool written and distributed by Chris Devrell. Customisation of EasyFind for inclusion in VBacs was performed by Christopher Rath.

Chris Devrell has kindly consented to allowing his EasyFind code to be embedded in VBacs, and to that end, EasyFind was modified to alter its key bindings to conform with Emacs; thus creating EasyFind for VBacs. EasyFind in its original unaltered state is available from http://www.cdev.co.uk/. Chris D. has other MS Word tools available on his website that you may find useful.

Known problems: this customised EasyFind still misbehaves from time-to-time. Assistance tracking down the following two minor issues would be appreciated:

EasyFind for VBacs differs from classic EasyFind in the following manner:

Miscellaneous Notes

A similar set of macros is available from http://www.wordstar.org/ for those who would rather be using WordStar than MS Word.  Note that the WordStar template file completely reorganizes MSWord’s menu structure to match WordStar 7 for MS-DOS's.

A new and very interesting competitor to VBacs has recently (circa 2005) appeared: XKeymacs. XKeymacs allows you to use Emacs key bindings with any MS Windows application. I’ve been trying it out, and while it has a few quirks it is quite usable. That said, I attempted to use XKeymacs for a couple of weeks and in my (albeit limited) experience the XKeymacs bindings are too much of a dislocation for me: someone who has used both Unix and MS-DOS/Windows since 1985.  For me, the VBacs key bindings are a reasonable compromise between MS Windows' shortcuts and Emacs bindings; whereas XKeymacs often conflict with the Windows key bindings for which there are no Emacs equivalents. I will monitor XKeymacs progress with interest, and should its bindings become more easily configurable.

For a PowerPoint key re-binding Add-In see OfficeOne Shortcuts for PowerPoint (http://officeone.mvps.org/ppshortcuts/ppshortcuts_link.html). I have looked at attempting to port VBacs to PowerPoint; however, PowerPoint does not natively support the kind of wholesale key rebinding that Word supports. The only way to accomplish the task is to capture and process every key press; which is what OfficeOne Shortcuts for PowerPoint claims to do.

Release History

v3.06 [2013-10-18] — Corrected a bug where Ctrl-D and [DEL] didn’t reset the VBacs selection toggle.

v3.05 [2013-07-11] — Corrected a bug where a VBA threw an error when copy or cut were attempted but no text was selected.

v3.04 [2013-02-17] — Corrected a bug where Ctrl-L didn’t work if the vertical scroll bar was not visible.

v3.03 [2010-09-21] — Correct another EasyFind bug—this one is a window interaction issue that occurs on Windows 7 (64 bit) platforms: when the EasyFind panel attempts to close itself and hand control back to the MS Word document window, control is incorrectly passed to Windows Explorer.

v3.01 [2010-07-20] — Correct EasyFind bug that was introduced in v3.00; where the panel is opened with the previous search string still appearing. Corrected an EasyFind bug where when the previous search string was recalled (by pressing [C]s or [C]r with an empty search field) EasyFind didn’t immediately search for the value.

v3.00 [2010-07-14] — First MS Word 2007 native version. Made VBacsPastePlain() much more robust. Fixed Ctrl-X, O (other-window), which had been broken by Word 2007. We now cache VBacs.ini file values; to speed up execution when querying them. Extended “Universal Argument” applicability to a few more cursor movements. Enhanced copy function with a CollapseSelectionOnCopy options setting.

v2.17 [2007-07-31] — Fixed mis-assigned Alt+Backspace key binding (Ctrl+Backspace was inadvertently assigned instead when the VBacsDeleteWordLeft function was created). Removed binding of Ctrl+Left and Ctrl+Right to associated VBacs due to conflicts with Outlook.

v2.16 [2007-07-30] — Changed VBacsEditCopy to collapse to the appropriate end of the selection based on Selection.StartIsActive. Bound Ctrl+C to VBacsEditCopy. Added VBacsSent{Left,Right} (bound to Alt+A and Alt+E respectively) to utilize internalExtendMode. In VBacsEditCopy, test that the start and end of the range are not equal prior to calling Selection.Range.Copy (otherwise an error is thrown when no selection is present). Added VBacsDeleteWord{Left,Right} which honour the universalArgument.

v2.15 [2007-07-29] — Added VBacsEditCut, VBacsEditCopy and associated key bindings. Added a new Ctrl+Q, V binding to allow access to MS Word’s actual EditCut command (which is usually bound to Ctrl+V). Corrected VBacsCapitalizeWord, VBacsDowncaseWord and VBacsUpcaseWord so that they move to the end of the selection and reset internalExtendMode and the universalArgument. Extended VBacsOpenLineAbove to use the universalArgument. Fixed VBacsTransposeChars and VBacsTransposeWords so that they reset internalExtendMode and the universalArgument. Added smart paste save-restore code to VBacsTransposeWords. Added a Bugs section to the documentation.

v2.14 [2007-07-23] — Assigned PageUp and PageDown keys to VBacsPageUP and VBacsPageDown, respectively. Added VBacsParaUp, VBacsParaDown, VBacsGoToNextPage, and VBacsGoToPreviousPage functions and associated key bindings. Fixed VBacsClearToEndOfLine so that it resets internalExtendMode; it also now resets the universalArgument even though it doesn't use it.

v2.13 [2007-07-16] — Fixed Ctrl+@ assignment (it needed to be assigned to VBacsSetMark) and the key binding documentation for “Set Mark”. Assigned the up-down-left-right cursor keys to the appropriate internal VBacs cursor move functions (to match Ctrl+F, Ctrl+P, etc.). Note: not all of the cursor movement bindings have been converted to use the new internal set mark method; the remaining bindings will be converted as we have time to complete the work.

v2.12 [2007-07-12] — Implemented basic support for Emacs’ universal-argument function (Ctrl+U), with extend mode remaining active after a movement command is issued using the universal-argument. Removed the various MoveXXX4 methods as they are now redundant. Added VBacsCancel (bound to Ctrl+G) which will cancel extend mode and also remove the selection highlight, as per Emacs. Added VBacsExchangePointAndMark (bound to Ctrl+X, X). This switches the logical insertion point between the start and end of the selection, allowing either end of the selection to be expanded or contracted. All the preceding changes in this release were coded by John Cooper; John’s contributions over the past couple of years are significant enough that he is now listed as co-author. Also in this release is the correction of a bug in EasyFind; where PageUp and PageDown key presses were ignored by the EasyFind panel.

v2.11 [2007-06-28] — Added error handling code to VBacsClearToEndOfLine() in order to fix bad behaviour in certain circumstances when the insertion point is at the end of a line.

v2.10 [2007-03-18] — When reading & writing the VBacs.ini file, VBacs now checks for the Operating System type and accordingly uses either a slash or backslash.

v2.09 [2007-02-15] — Updated Ctrl-u n, Ctrl-u p, Ctrl-u f, & Ctrl-u b interact with use selected text; they now attempt to extend a selection if the user has already selected text.

v2.08 [2007-01-04] — Added beginning of sentence (Alt-a) and end of sentence (Alt-e) bindings.

v2.07 [2006-03-13] — Corrected reverse search bug: “In reverse incremental search (^R), the cursor moves back one hit per keystroke, even if that key matches the current hit. It should remain on the current word until/unless the added letter fails to match in the current word. E.g.,: type: ^R f l a s h in a document containing many instances of the word "flash". '^Rf' moves back to the nearest previous f-word, 'l' backs up to the nearest fl-word,.... If we are now on the word ‘flash’ but keep typing , 'a' backs up to the nearest fla-word, and so on, even though 'fla' matches the present word and no more searching is necessary.” The fix I have applied is not without its faults: after pressing ^R to find preceding occurrences, if you extend the search string the search begins again where you began your search.

v2.06 [2005-10-27] — Added extra code to the Ctrl+L binding so that it better emulates Emacs recenter binding.

v2.05 [2005-10-09] — Added Ctrl+L binding.

v2.04 [2005-09-30] — Added Ctrl+Alt+% binding (in Emacs this invokes “Query Replace regexp”, but here in VBacs we simply open the Find-Replace panel). Fixed a problem where EasyFind wasn’t properly detecting a number of non-alphanumeric key presses.

v2.03 [2005-09-27] — Added Ctrl-Q,N binding.

v2.02 [2005-09-25] — Added EasyFind (see above), added Alt+G binding to Goto Line panel, and added a VBacs Options panel (see above).

v2.01 [2005-06-25] — Removed Alt+G key bindings that had crept into this package, but are not Emacs bindings.

v2.00 [2005-06-08] — Some VBacs behaviours have fundamentally changed, so I have decided to increment the major version number in acknowledgement of those changes! Added a VBacs.ini file (see above for details), changing Ctrl+T and Alt+T so that they refuse to run when a region of text is selected, and added two configuration variables to enable alternate behaviour for character transpose and kill to end of line. Added enhancements and corrections submitted by John Cooper: Ctrl-O conforms to Emacs behaviour (“insert newline and leave point before it”); corrected Ctrl+T so that it functions correctly if the user has SmartPaste enabled; implemented more Emacs-like search-forward/backward functionality, including regular expression searches (the old MS Word function is available through Ctrl-Q); added 4 “universal-argument” prefixed commands to move the cursor 4 lines/characters at a time (Ctrl+U P; Ctrl+U N; Ctrl+U F; Ctrl+U B) and made old MS Word underline function available through Ctrl+Q prefix; added Ctrl+/ as another binding for undo; added an extra header to the “Template_Setup” module to explain that it is no longer used; enabled Alt+B in Outlook; changed Ctrl+K so that it puts the deleted region in the clipboard; added a Ctrl+Q function to enable access to the old Ctrl+K function.

v1.05 [2005-01- 23] — Ninth public release (via http://www.rath.ca/Misc/VBacs only). Added bindings for Paragraph Up/Down; fixed bug in VBacsOpenLineAbove() (it was misbehaving when the cursor was positioned at the start of the line); and fixed bug in VBacsTransposeChars() (it was transposing the wrong two characters). Thanks to Bill Zvonar for his bug report for the two functions.

v1.04 [2004-11-01] — Eighth public release (via http://www.rath.ca/Misc/VBacs only). Added Ctrl+Space, Ctrl+@, and Ctrl+Q,Space bindings. Also corrected some typos in the documentation herein.

v1.03 [2003-12-26] — Seventh public release (via http://www.rath.ca/Misc/VBacs only); corrected Ctrl+T binding (incorrectly assigned in last release), added an extra configuration step, and added binding Alt+%.

v1.02 [2003-12-24] — Sixth public release (via http://www.rath.ca/Misc/VBacs only); added bindings suggested by Matthew K. Junker and Doug Milliken; specifically, Ctrl+T; Alt+T; Ctrl+Q T; Alt+S; Ctrl+X B; Ctrl+X [; Ctrl+X ]; Ctrl+X H; Alt+G B; Alt+G I; Alt+G U.

v1.01 [2003-03-22] — Fifth public release (via http://www.rath.ca/Misc/VBacs only); added some missing bindings related to the use of panes (windows in Emacs terminology): “Crtl+X 0”; “Crtl+X 1”; “Ctrl+X 2”; and “Ctrl+X O”.  Note, MS Word only allows a document window to be split into 2 panes.

v1.00 [2001-01-13] — Fourth public release (via http://www.rath.ca/Misc/VBacs only, but announced in the microsoft.public.word.programming newsgroup); first release under the LGPL license.

v0.86 [2001-01-10] — Third public release (via http://www.rath.ca/Misc/VBacs and the microsoft.public.word.programming newsgroup).

v0.xx [1999–2000] — Various updated versions sent to individuals requesting more current versions (via email).

v0.20 [1998-03-05] — Second public release (via the comp.lang.basic.visual.misc newsgroup).  Released under Perl’s Artistic license.

v0.10 [1998-03-03] — First public release (via http://www.wopr.com/ and the comp.lang.basic.visual.misc newsgroup).  Released under Perl’s Artistic license.

Old VBacs Releases

Older public releases of VBacs are available from the following links: v0.1, v0.2, v0.86, v1.01, v1.03, v1.04, v1.05, v2.00, v2.01, v2.02, v2.03, v2.04, v2.05, v2.06, v2.07, v2.08, v2.09, v2.12, v2.13, v2.14, v2.15, v2.16, v2.17, v3.00, v.3.01, v3.02, v3.03, v3.04.


©Copyright 1998-2013, Christopher & Jean Rath
Telephone: 613-824-4584
Address: 1371 Major Rd., Ottawa, ON, Canada K1E 1H3
Last updated: 2013/10/18 @ 14:41:34 ( )