A terminal text editor in OCaml, built on the twig buffer engine.
twig provides the engine — grapheme-aware Doc, Buf with
undo/redo and selection, Viewport with soft wrap, Markdown
tokenizer, Terminal raw-mode + kitty keyboard protocol,
Input decoding, and the Eio event loop. twig-edit is the
application layer on top: file open/save, search + replace,
syntax highlighting for a handful of languages, themes, and
the two-tier keybinding system.
- Grapheme-aware editing. Cursor never lands mid-cluster. ZWJ emoji, combining marks, CJK wide characters all handled.
- Soft wrap (Alt-Z). Long lines break at word boundaries; arrow keys navigate through wrapped segments.
- Syntax highlighting for C, OCaml, Dune, and Opam with
cross-line state (multi-line comments, nested OCaml
(* *)). - Two-tier commands. Shift+Space or Esc enters chord mode
with a status-bar legend; single keypresses fire common
actions. Press
:for a full text-prompt for complex commands. - Preview-first goto. Typing
goto 42highlights the target line before you commit. - Incremental search (Ctrl-F) with live match highlighting.
- Find and replace via
:replace <old> with <new>. - Selection, copy/cut/paste with OSC 52 clipboard.
- Undo/redo with keystroke burst grouping.
- Themes: default, nightwatch, solar, mono. Cycle with
tin chord mode or:theme <name>. - Line numbers (Alt-L), diff markers (Alt-D), auto-indent on Enter, block indent/outdent with Tab / Shift-Tab on selections, atomic save, open-file prompt (Ctrl-O), SIGWINCH-responsive resize.
Requires OCaml ≥ 5.2, dune ≥ 3.0, and twig installed (via
dune install in the twig
repo, or from opam once it's published there).
opam install . --deps-only
dune build
dune exec bin/main.exe -- [file]
dune runtest| Key | Action |
|---|---|
| Ctrl-S | Save |
| Ctrl-Z | Undo |
| Ctrl-Y | Redo |
| Ctrl-O | Open file |
| Ctrl-Q | Quit |
| Ctrl-F | Find |
| Ctrl-N | Next match |
| Ctrl-G | Set mark |
| Ctrl-C | Copy selection |
| Ctrl-X | Cut selection |
| Ctrl-V | Paste |
| Tab | Insert tab / indent selected block |
| Shift-Tab | Outdent selected block |
| Ctrl-Left / Ctrl-Right | Word motion |
| Ctrl-Home / Ctrl-End | Document start / end |
| Shift-Arrow | Extend selection |
| Alt-Z | Toggle soft wrap |
| Alt-L | Toggle line numbers |
| Alt-D | Toggle diff markers |
| Key | Action |
|---|---|
| s | Save |
| S | Save as |
| q | Quit |
| Q | Force quit |
| f | Find |
| r | Replace |
| g | Goto line (with preview) |
| t | Cycle theme |
| w | Toggle wrap |
| n | Toggle line numbers |
| D | Toggle diff markers |
| u | Undo |
| U | Redo |
| d | Duplicate line |
| h | Help |
| : | Full command prompt |
save | save as <path> | quit | q! | wq
goto <n> | g <n> | top | bottom
replace <old> with <new>
dup [n]
theme [name]
help
twig-edit depends on twig. The library split:
Twig.*(engine, in twig) —Doc,Buf,Grapheme,Viewport,Layout,Markdown,Theme,Terminal,Input,Loop,Clipboard,Rect,Position.Twig_edit.*(this repo,lib/) —State,Command,Render,Syntax,Ui,Palette,Clipboard.
Twig_edit.State wraps Twig.Buf with editor-specific state
(filename, dirty flag, search state, modes, theme). Command
is an ADT for every editor action; bin/main.ml maps input
events to Command.t and State.apply executes them. Render
draws the editor frame on top of the engine's primitives.
MIT