Overview
TheKeyMap class provides a flexible key binding system that maps keyboard input sequences to editor commands. It supports complex key sequences, digit capture for counts, register specification, and custom character capture.
Core Classes
KeyMap
The main keymap structure that stores command bindings in a tree structure.ignoreFinalDigit- Whether to ignore trailing digits in key sequencesspRoot- Root node of the command tree
CommandNode
Represents a node in the keymap tree, allowing for hierarchical command structures.<D>- Captures digits (for counts)<R>- Captures register names<.>- Captures any single character
KeyMapResult
Contains the result of a keymap lookup, including captured values and the matched command.captureNumbers- Numeric counts captured from the key sequencecaptureChars- Individual characters capturedcaptureRegisters- Register names capturedneedMoreChars- True if more input is needed to complete the commandfoundMapping- The command ID that was matchedsearchPath- The path taken through the keymap tree
TotalCount()- Returns the sum of all captured numbers, or 1 if noneRegisterName()- Returns the first captured register, or 0 if none
Functions
keymap_add
Adds a new key binding to one or more keymaps.maps/map- Target keymap(s) to add the binding tostrCommand- Key sequence(s) that trigger the commandcommandId- Command identifier to executeopt- Whether to replace existing bindings or only add new ones
true if the binding was added successfully
Example:
keymap_find
Searches for a command binding matching the given key sequence.map- Keymap to searchstrCommand- Key sequence to look upresult- Output parameter containing the search result
keymap_dump
Outputs the entire keymap structure for debugging.map- Keymap to dumpstr- Output stream to write to
KeyMapAdd Enum
Controls how new bindings interact with existing ones.Built-in Command IDs
Zep provides numerous pre-defined command IDs for common operations:Mode Commands
id_NormalMode,id_InsertMode,id_VisualMode,id_ExModeid_VisualLineMode
Motion Commands
id_MotionUp,id_MotionDown,id_MotionLeft,id_MotionRightid_MotionWord,id_MotionBackWord,id_MotionEndWordid_MotionWORD,id_MotionBackWORD,id_MotionEndWORDid_MotionLineBegin,id_MotionLineEnd,id_MotionLineFirstCharid_MotionPageForward,id_MotionPageBackwardid_MotionGotoLine,id_MotionGotoBeginning
Edit Commands
id_Delete,id_DeleteLine,id_DeleteWord,id_DeleteToLineEndid_Yank,id_YankLineid_PasteBefore,id_PasteAfterid_ChangeLine,id_ChangeWord,id_ChangeToLineEndid_Substitute,id_SubstituteLineid_Undo,id_Redo
Insert Commands
id_InsertCarriageReturn,id_InsertTab,id_Backspaceid_Append,id_AppendToLineid_OpenLineBelow,id_OpenLineAbove
Search Commands
id_Find,id_FindBackwards,id_FindNextid_QuickSearch
Standard Mode Commands
id_StandardCopy,id_StandardPaste,id_StandardSelectAllid_MotionStandardUp,id_MotionStandardDownid_MotionStandardLeftSelect,id_MotionStandardRightSelect
include/zep/keymap.h:20-173 for the complete list.
