EditorMode Enum
Zep defines several editor modes: Frominclude/zep/mode.h:66-73:
Normal Mode
Vim-style command mode for navigation and operations
Insert Mode
Text insertion mode, default for standard editors
Visual Mode
Visual selection mode for Vim-style text objects
Ex Mode
Command-line mode for ex commands (
:w, :q, etc.)ZepMode Base Class
All modes inherit from theZepMode base class:
From include/zep/mode.h:151-156:
Key Mode Methods
AddKeyPress
AddKeyPress
Purpose: Process a single key pressParameters:
key- The character or special key codemodifierKeys- Ctrl, Alt, Shift flags
- Convert key to internal representation
- Append to command string
- Check keymap for matching command
- Execute command if found
HandleMappedInput
HandleMappedInput
Purpose: Execute commands once key sequence is recognizedWorkflow:
- Parse command string
- Extract counts, registers, operators
- Build CommandContext
- Execute buffer operations
- Switch modes if necessary
GetCommand
GetCommand
Purpose: Parse the command context from input stringReturns:
true if valid command foundSets up:- Operation type (delete, copy, paste)
- Range to operate on
- Register to use
- Count multiplier
Built-in Modes
Vim Mode
Frominclude/zep/mode_vim.h:22-55:
Vim mode provides full modal editing with operators, motions, text objects, and ex commands. It starts in Normal mode.
Vim Mode Features
- Operators:
d(delete),c(change),y(yank),p(paste) - Motions:
h/j/k/l,w/b/e,0/$,gg/G - Text Objects:
iw(inner word),aw(a word),i(,a{ - Counts:
3dd,5w,2j - Registers:
"ayw,"bp - Dot Command:
.repeats last change - Visual Mode:
v,V,Ctrl-v - Ex Commands:
:w,:q,:s/find/replace/
Standard Mode
Frominclude/zep/mode_standard.h:8-28:
Standard mode behaves like typical modern editors - you’re always inserting text, and modifier keys (Ctrl+C, Ctrl+V) perform operations.
Standard Mode Features
- Direct text insertion (no mode switching)
- Ctrl+C / Ctrl+V for copy/paste
- Shift+arrows for selection
- Ctrl+arrow keys for word movement
- Home/End for line navigation
- Standard undo/redo (Ctrl+Z / Ctrl+Y)
Key Processing Flow
Keymaps
Modes use keymaps to translate input sequences to commands: Frominclude/zep/mode.h:237-240:
KeyMap Structure
Keymaps support:- Multi-key sequences:
gg,dd,ci( - Counts:
3j,5dd - Registers:
"a,"b - Modifier keys:
<C-w>,<C-r>
Example Keymap Registration
Example Keymap Registration
Command Context
When a command is recognized, aCommandContext is built:
From include/zep/mode.h:114-149:
Command Operations
Frominclude/zep/mode.h:75-85:
Mode Switching
Frominclude/zep/mode.h:182:
- User presses mode change key (Vim:
i,v,Esc,:) - Command completes and specifies mode switch
- Ex command executed (e.g.,
:visual)
Mode switching updates the cursor appearance, key mappings, and editing behavior.
Cursor Types
Frominclude/zep/mode.h:180:
- Normal Mode: Block cursor
- Insert Mode: Line cursor
- Visual Mode: Block cursor (with selection highlight)
Implementing Custom Modes
To create a custom mode:- Inherit from ZepMode
- Override Init() to setup keymaps
- Handle input in AddKeyPress() or override HandleMappedInput()
- Register with editor
Modifier Keys
Frominclude/zep/mode.h:55-64:
Special Keys
Frominclude/zep/mode.h:19-52:
Special keys are mapped to values 0-31 (below ASCII space) to avoid conflicts with printable characters.
Undo and Redo
Modes provide undo/redo operations: Frominclude/zep/mode.h:177-178:
Next Steps
Buffers
Learn how modes interact with buffer operations
Display Layer
Understand how modes affect rendering
