My configuration of Excel vba to use Emacs key bindings
- Emacs-like selection moving (forward:
C-f
, backward:C-b
, next:C-n
, previous:C-p
) - Move end/start in the active row (end:
C-e
, start:C-a
) - Kill/Insert row (kill:
C-k
insert:C-i
) - Keep windows common keybindings (Copy:
C-c
, Paste:C-v
, Cut:C-x
) - Scroll up/down (up:
C-u
, down:C-d
) - Other powerful functions
SheetForward
/SheetPrevious
: Select the next/previous sheetCreateSheet
: Create the new sheet named by your inputMoveRow
/MoveCol
: Move the selection toward the row/column direction by inputted number/alphabet
- Refered to EmacsMode.bas in this
- Excel
I saw this program work on Excel 2007 and Windows7.
Import the module file (myEmacsKey.bas
) as the standard module and execute the procedure MyEmacsMode
.
- Open the Excel book.
- Click Developer>”Visual Basic” on Ribbon (or Alt + F11).
→ VBE (Visual Basic Editor) is opened
- Select the desired project in Project explorer and File>”Import File…” on menu bar (or right click on the desired project and click “Import File…”)
- Select the module file (
myEmacsKey.bas
) and import.→ The new module is created under the module hierarchy on “Project explorer”
- Return to the Excel book window and click Developer>macro on Ribbon and execute
MyEmacsMode
.
Create Personal.xlsb (which is always opened internally ,whatever book is opened) and
import the module file (myEmacsKey.bas
) on it.
Additionaly you have to register MyEmacsMode
procedure as follows so that
it can be read every time the book is opened.
- Create Personal.xlsb seeing Copy your macros to a Personal Macro Workbook. You may delete the macro which is made only to create this file.
- Open VBE and import above module files.
- The following codes are put into
ThisWorkbook
under the project ofPERSONAL.xlsb
. The procedureMyEmacsMode
is read every time Excel is opened.
Private Sub Workbook_Open() Call MyEmacsMode End Sub
Key Binding | Function Name | Description |
---|---|---|
C-f | ForwardCellModified | select forward cell |
C-b | BackwardCell | select backward cell |
C-n | NextLineModified | select next line |
C-p | PreviousLine | select previous line |
C-M-f C-M-b | MoveCol | Move the selection to the row directed by the inputted number |
C-M-n C-M-p | MoveRow | Move the selection to the column directed by the inputted alphabet |
M-g | MoveRowCol | Move the selection to the cell directed by inputted ID |
C-l | Recenter | Scroll up/down to center the active row |
C-u | ScrollUp | Scroll up by one page |
C-d | ScrollDown | Scroll down by one page |
C-M-j | SmallScrollDown | Scroll down by one row |
C-M-k | SmallScrollUp | Scroll up by one row |
C-M-l | SmallScrollRight | Scroll right by one column |
C-M-h | SmallScrollLeft | Scroll left by one column |
C-+ | WindowZoom | zoom in the active window |
C-- | WindowShrink | zoom out the active window |
C-TAB | SheetForward | Select the forward sheet |
C-S-TAB | SheetPrevious | Select the previous sheet |
C-! | FirstSheet | Select the first sheet |
C-( | LastSheet | Select the last sheet |
C-k | KillRow | Kill the active row |
C-S-k | KillMultipleRow | Kill the multiple rows by the inputted number |
C-i | InsertRow | Insert a new row |
C-S-i | InsertMultipleRow | Insert the multiple rows by the inputted number |
M-< | BeginningOfUsedRange | Select the first cell in the used range |
M-> | EndOfUsedRange | Select the last cell in the used range |
C-M-a | BeginningOfUsedRangeRow | Move the selection to the first row in the used range |
C-M-e | EndOfUsedRangeRow | Move the selection to the last row in the used range |
C-g | GroupCommand | Group the selected shapes |
C-u | UnGroupCommand | Ungroup the selected group shape |
C-t | CreateSheet | Create the new sheet you named after the active sheet |
C-s | Search | Open the search dialog |
C-r | Replace | Open the replace dialog |
C-y | paste | original paste |
M-s | MySaveFile | Save the book |
C-M-r | MyFindFile | Open the dialog and select the file to be opened |
S-ESC | Enable_Keys | Deactivate this emacs key bindings |
Since the configuration meets only my needs,
I encourage you to modify some configurations especially about key bindings.
Modifying is enabled only by modifying imported module directly on VBE or by
importing the module file (myEmacsKey.bas
) you edited.
- Move the window of InputBox where it does not prevent viewing
- Use the other input method not to create the window instead of using InputBox
- I want to assign
C-M-...
commands toM-...
keys, but manyM-...
keys were shadowed by the default access keys. I want to make them disable. - Translate
C-m
intoEnter
like Emacs - Create the
undo
procedure