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.

Note re: Word 2013 and 2016 — Starting with Word 2013, Microsoft has
made some material changes the Word object model; specifically, w.r.t. comments.
These changes completely break VBacs' internal extend mode emulation and the
universal argument handling. So, these features have been removed for the
time being in VBacs 4.0.

For Word 2013 and higher:VBacs_4.0.zip — The macros are copyrighted,
but are distributed under the GNU Lesser Public License.

For Word 2007 and higher:VBacs_3.08.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.07.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.

Contributors

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

Yasser Hajivalizadeh — May, 2013 — pointed out a bug which caused an error if a copy or cut was attempted when no text was selected.

John Cooper — February & July, 2007; May, September, & October, 2005 — the new functionality in version 2.0 was either directly contributed by John, or was a result of interaction with him. John is also directly responsible for suggesting and then arranging for permission to have EasyFind (see below) included in VBacs. John also suggested the ScrollIntoView view method as a “better than nothing” substitute for Ctrl+L (recenter) and the manner in which Ctrl-U[up] selection works. The functionality in version 2.12 was also contributed by John.

Gary Mamon — March, 2007— pointed out a problem with VBacs under MS Word on MacOS.

VBacs version 3.xx is only compatible with MS Office 2007 through 2010. Microsoft changed the MS Word object model in 2013 and this broke the universal argument and internal ExtendMode handling in VBacs.

VBacs version 4.xx has only been tested on MS Office 2016; however, it should work on all versions starting with 2007. The universal argument and internal ExtendMode code has been removed from VBacs v4.xx. In place of ExtendMode emulation, key bindings to MS Word’s own extend movement functions have been added (see
Handy Non-Emacs Bindings, below).

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

Copy and paste behaviours are still a bit wonky starting with Word 2013: VBacs copy actions don’t always have any effect, and VBacs paste actions don’t always paste the format one expects. As I explore Word 2016 I will continue to try and the debug copy-paste functionality.

Installation Instructions

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

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]).

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.

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.

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)

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).

Restart MS Word.

Read the “Configuration Instructions” section, below, and decide if you need to edit VBacs.ini.

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

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….

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

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

Increase Indent

Ctrl+X TAB

Handy Non-Emacs Bindings

Action

Key
Binding

Paste Plain (see note, below)

Ctrl+Shift+Y

Decrease Indent

Ctrl+X Shift+TAB

Line Up Extend Selection

Ctrl+Shift+P

Line Down Extend Selection

Ctrl+Shift+N

End of Line Extend Selection

Ctrl+Shift+E

Start of Line Extend Selection

Ctrl+Shift+A

Character Forward Extend Selection

Ctrl+Shift+F

Character Backward Extend Selection

Ctrl+Shift+B

Word Forward Extend Selection

Alt+Shift+F
Ctrl+Shift+Right

Word Backward Extend Selection

Alt+Shift+B
Ctrl+Shift+Left

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:

Regarding “Universal Argument”: this applies to the simple movement commands (by character,
word, line) and only currently supports incrementing the “magnification” factor by multiples of
4.

In Emacs, the Ctrl-K command appends to the clipboard under certain circumstances and overwrites
the clipboard in others. In VBacs, this is not possible, and Ctrl-K always overwrites the clipboard.

The ^X style Emacs commands can not be mapped directly into VBA macros because VBA’s keyboard
access is so limited: the second key in a two key command sequence may not be an Alt or Ctrl key-combination.
This means that VBacs will only ever be a partial implementation of the Emacs command set.

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:

multiple erroneous key-presses are detected by EasyFind—which causes the EasyFind panel to be
dismissed and then the highlighted characters to be replaced with the erroneous key-presses (note,
this problem has only been observed under Windows XP Tablet edition)

EasyFind only recognises a single character—when EasyFind is stuck in this mode the only “fix”
is to open MS Word’s native find panel and perform a search; which somehow resets MS Word’s find
method and EasyFind begins to work properly again

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

the VBacs version implements Emacs key bindings; whereas the original version stays true to
MS Word’s native shortcut keys

the VBacs version takes any unrecognised key presses and attempts to pass those back to the
window that called EasyFind (closing itself in the process)

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

v4.00 [2016-05-30] — First
MS Word 2016 native version.

v3.07 [2016-03-30] — Added key bindings for IncreaseIndent and DecreaseIndent. The former corresponds to the Emacs function indent-rigidly. I did not implement the prefix functionality.

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.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.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.