Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 115
نمايش فراداده

Hack 80 Emulate Emacs with VBacs

You've already learned all those Emacs commands, so you might as well use them. This set of freeware macros replicates many common Emacs keyboard shortcuts within Word.

Emacs, a text editor usually associated with the Unix operating system (though it's available on most any platform), is in most ways the polar opposite of Word. No one just sits down with Emacs, expecting to hunt around a few menus to find the commands they need. While you can learn simple commands quickly, true Emacs mastery is a lifelong love affair for hackers around the world.

Emacs was born at a time when a window still meant something you opened to let in fresh air. You had to use the keyboard to issue every command, and often they required complex key combinations, such as Ctrl-X, Ctrl-S (the command to save the current file).

Though versions of Emacs have since been developed that include menus and even toolbars, most Emacs users rarely take their hands off the keyboard. So when someone who's mastered all those Emacs commands switches to Word, it can be a frustrating experience.

Fortunately, the free VBacs template, available for download at http://rath.ca/Misc/VBacs, modifies Word's key bindings to more closely match the native ones in Emacs and can make Word feel a little more like home.

Word does support two-stage key bindings (such as Alt-L, S), but you can use the Ctrl key only in the first stage. This makes it impossible to recreate many Emacs commands, such as Ctrl-X, Ctrl-S. In these cases, VBacs gets as close as Word will permit; for example, Ctrl-X, S lets you save.

9.2.1 Installing VBacs

VBacs is offered as a standard .dot template file, released under the GNU Lesser Public License. Here's how to install the VBacs template as a global template that will automatically load every time you start Word.

First, download the VBacs template to your computer. Make sure you close Word and any other applications that may access Word, such as Outlook.

Next, locate your Word Startup folder, which is usually the following:

C:\Documents and Settings\username\Application Data\Microsoft\Word\STARTUP

If you're not sure where your STARTUP folder is located, you can open Word and select ToolsOptions, click the File Locations tab, and make a note of the folder listed under STARTUP.

After you put VBacs.dot into your STARTUP folder, its key bindings will take effect the next time you start Word.

9.2.2 Using VBacs

Table 9-1 summarizes the VBacs commands and their key bindings. Some aren't actually Emacs commands or differ slightly from their Emacs counterparts.

Table 9-1. VBacs commands and key bindings

VBacs action

Key binding

Line up

Ctrl-P

Line down

Ctrl-N

End of line

Ctrl-E

Start of line

Ctrl-A

Start of buffer

Shift-Alt-<

End of buffer

Shift-Alt->

Character forward

Ctrl-F

Character backward

Ctrl-B

Word forward

Alt-F

Word backward

Alt-B

Page down

Ctrl-V

Page up

Alt-V

Go to previous page

Ctrl-X, [

Go to next page

Ctrl-X, ]

Search

Ctrl-S, Ctrl-R

Replace

Alt-%

Cut selection

Ctrl-W

Paste selection

Ctrl-Y

Copy selection

Alt-W

Select whole buffer

Ctrl-X, H

Delete word

Alt-D

Word delete

Alt-Backspace

Delete

Ctrl-D

Delete to end of line

Ctrl-K

Edit undo

Shift-Ctrl

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

Ctrl-X, U

Open line above

Ctrl-O

Capitalize word

Alt-C

Upshift word

Alt-U

Downshift word

Alt-L

Delete window

Ctrl-X, 0

Close other windows

Ctrl-X, 1

Split window vertically

Ctrl-X, 2

Other window

Ctrl-X, O

Switch to buffer

Ctrl-X, B

Iconify MS Word

Ctrl-Z

Center paragraph

Alt-S

Transpose characters

Ctrl-T

Transpose words

Alt-T

Paste plain (unformatted text)

Ctrl-Shift-Y

Select all

Ctrl-Q, A

Bold

Ctrl-Q, B

Italic

Ctrl-Q, I

Print

Ctrl-Q, P

Hanging indent

Ctrl-Q, T

Tab (in a table)

Ctrl-Q, Tab

With VBacs installed, several editing and navigation tasks become immediately easier. For example, Ctrl-X, 2 splits the active window vertically, as shown in Figure 9-1.

Figure 9-1. Quickly split a window with Ctrl-X, 2 in VBacs

The shortcut Ctrl-O (open line above) creates a new line above the cursor and then moves the cursor to the beginning of the new line. One more notable gem: Ctrl-K deletes from the cursor to the end of a line. In Word, navigating and editing by lineas opposed to by paragraphcan be tricky. With VBacs, it becomes a lot more manageable.

If you want to temporarily remove the VBacs key bindings, select ToolsTemplates and Add-ins and uncheck VBacs.dot in the list of installed add-ins. When you click the OK button, Word will unload the template, and your key bindings will return to Word's default settings. VBacs will return the next time you start Word. To uninstall VBacs, just remove it from Word's STARTUP folder.

For more information on Emacs, check out http://www.gnu.org/software/emacs/emacsl and Learning GNU Emacs (O'Reilly).

Christopher Rath