Skip to content

Instantly share code, notes, and snippets.

@pwgerman
Created May 15, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwgerman/49a8f1a9a69c6b0d86eb to your computer and use it in GitHub Desktop.
Save pwgerman/49a8f1a9a69c6b0d86eb to your computer and use it in GitHub Desktop.
A VBA macro to set up Emacs keybindings in MS Word
Attribute VB_Name = "NewMacros"
Sub EmacsCustomKeybind()
Attribute EmacsCustomKeybind.VB_Description = "Assigns emacs and other useful keybindings to Keyboard Customization."
Attribute EmacsCustomKeybind.VB_ProcData.VB_Invoke_Func = "Normal.NewMacros.Emacs1"
'
' Emacs1 Macro
' Assigns emacs and other useful keybindings to Keyboard Customization.
'
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyB, wdKeyOption, wdKeyControl), _
KeyCategory:=wdKeyCategoryCommand, Command:="WordLeft"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyB, wdKeyShift, wdKeyOption, _
wdKeyControl), KeyCategory:=wdKeyCategoryCommand, Command:= _
"WordLeftExtend"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyP, wdKeyShift, wdKeyControl), _
KeyCategory:=wdKeyCategoryCommand, Command:="LineUpExtend"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyN, wdKeyShift, wdKeyControl), _
KeyCategory:=wdKeyCategoryCommand, Command:="LineDownExtend"
CustomKeybind_DeleteChar
End Sub
Sub DeleteChar()
Attribute DeleteChar.VB_Description = "Forward delete one char to the right"
Attribute DeleteChar.VB_ProcData.VB_Invoke_Func = "Normal.NewMacros.EditBack1"
'
' EditBack1 Macro
' Forward delete one char to the right
'
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
End Sub
Sub CustomKeybind_DeleteChar()
Attribute CustomKeybind_DeleteChar.VB_ProcData.VB_Invoke_Func = "Normal.NewMacros.Add_delete_macro_shortcut"
'
' Add_delete_macro_shortcut Macro
'
'
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyD, wdKeyControl), KeyCategory:= _
wdKeyCategoryMacro, Command:="DeleteChar"
End Sub
@christopher-rath
Copy link

You might also try my MS Word add-in: https://rath.ca/Misc/VBacs/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment