Vim Mode
February 18, 2026 · View on GitHub
Overview
Optional modal editing mode that adds Vim-style keybindings to FerriteEditor. Disabled by default to preserve standard editing behavior. When enabled, provides Normal/Insert/Visual/Visual Line modes with essential Vim commands.
Key Files
src/config/settings.rs-vim_mode: boolsetting (default:false)src/editor/ferrite/vim.rs-VimStatestruct,VimModeenum,handle_key()dispatchersrc/editor/ferrite/editor.rs- Event loop interception,set_vim_mode()/vim_mode()methodssrc/editor/widget.rs-vim_modebuilder method,vim_mode_labelonEditorOutputsrc/app/central_panel.rs- Propagates setting to EditorWidget, surfaces mode to UiStatesrc/app/status_bar.rs- Renders[NORMAL]/[INSERT]/[VISUAL]/[V-LINE]indicatorsrc/ui/settings.rs- Vim Mode checkbox in Editor settings sectionsrc/state.rs-vim_mode_indicator: Option<&'static str>onUiState
Architecture
Data Flow
Settings.vim_mode ──► EditorWidget.vim_mode() ──► FerriteEditor.set_vim_mode()
│
VimState.handle_key()
│
VimMode (label: &'static str)
│
EditorOutput.vim_mode_label
│
UiState.vim_mode_indicator
│
status_bar.rs (renders indicator)
Modal State Machine
VimState manages the current mode and pending operations:
- Normal: Default mode. Keys are interpreted as commands (motions, operators, mode switches).
- Insert: Text input mode. All keys pass through to normal editor handling.
Escreturns to Normal. - Visual: Character-wise selection. Motions extend selection.
d/yoperate on selection. - Visual Line: Line-wise selection. Similar to Visual but selects full lines.
Event Loop Integration
In FerriteEditor::ui(), when vim_mode_enabled is true:
Event::Keyevents are intercepted byVimState::handle_key()before normal processing.- Returns
VimKeyResult::Handled(result)if Vim consumed the key,Passthroughif not. Event::Textevents are suppressed in Normal/Visual modes viashould_insert_text().- Standard egui shortcuts (Ctrl+C, Ctrl+V, etc.) are not intercepted by Vim.
Implemented Commands
Normal Mode
| Key | Action |
|---|---|
h/j/k/l | Left/down/up/right movement |
w/b/e | Word forward/backward/end |
0/$ | Line start/end |
gg/G | File start/end |
i/a | Insert before/after cursor |
I/A | Insert at line start/end |
o/O | Open line below/above |
x | Delete character |
dd | Delete line |
yy | Yank line |
D | Delete to end of line |
C | Change to end of line |
p/P | Paste after/before |
v/V | Enter Visual/Visual Line mode |
u | Undo |
Ctrl+R | Redo |
{count}{motion} | Repeat count (e.g., 3j = move down 3) |
Visual/Visual Line Mode
| Key | Action |
|---|---|
| Motions | Extend selection |
d | Delete selection |
y | Yank selection |
Esc | Return to Normal |
Dependencies Used
No additional crates. Built entirely on existing TextBuffer, Cursor, and Selection types.
Usage
- Open Settings (gear icon or Ctrl+,)
- In the Editor section, check "Vim Mode"
- Status bar shows
[NORMAL]when active - Press
ito enter Insert mode,Escto return to Normal - Disable the checkbox to return to standard editing