Ratatui Code Editor widget
A code editor widget for Ratatui, built with syntax highlighting powered by Tree-sitter.
Demo

Features
- π¨ Syntax Highlighting - Powered by Tree-sitter with support for multiple languages
- π Text Editing - Full text editing capabilities with cursor movement
- π±οΈ Mouse Support - Mouse clicks, scroll, text selection, words and lines snapping supported
- π Copy/Paste - Clipboard integration with system clipboard
- π Undo/Redo - Full history management for edit operations
- π― Text Selection - Visual text selection with keyboard and mouse
- π Themes - Customizable color themes for syntax highlighting
- π± Responsive - Adapts to terminal window size changes
- π Visual Marks - Mark specific regions in the editor
- π§© Emoji/Unicode Aware - Correct widths, cursor, and selection for grapheme clusters (e.g., β€οΈ)
Syntax Highlighting: Fast, Cached, and Wide-Row Ready
The Ratatui Code Editor features blazing fast syntax highlighting powered by Tree-sitter. Tree-sitter incrementally parses your code in real time, enabling blazing fast, accurate and context-aware highlighting for all supported languages.
Performance Features:
- Super Fast: Only the visible portion of the code is highlighted on each render, making even large files feel snappy.
- Smart Caching: Highlighting results are cached per visible region, so scrolling and editing are smooth and efficient.
- Wide Row Support: Handles long lines and wide code gracefully, ensuring correct highlighting and cursor placement even with complex Unicode or tab characters.
This approach means you get instant, editor-quality highlighting in your terminal, with no lagβeven for big files or wide code blocks.
Supported Languages
- Rust
- Python
- JavaScript
- TypeScript
- C
- C++
- Go
- C#
- Java
- Html
- Css
- Yaml
- Toml
- Json
- Bash
- Markdown
Quick Start
Add this to your Cargo.toml:
= "1.0"
= "0.29"
= "0.29"
= { = "https://github.com/vipmax/ratatui-code-editor" }
Basic Usage
use ;
use ;
use Editor;
use vesper;
use stdout;
Examples
Run the included examples to see the editor in action:
# Minimal editor example
cargo run --release --example minimal
# Half-screen editor
cargo run --release --example half
# Split-screen editor
cargo run --release --example split
# Editor
cargo run --release --example editor <filename>
Key Bindings
Navigation
- Arrow Keys - Move cursor
Editing
- Any printable character - Insert character
- Delete - Delete characters
- Enter - Insert new line
- Tab - Insert tab or spaces
- Ctrl+D - Duplicate
- Ctrl+X - Cut
- Alt+Enter - go to next line
- Alt+/ - comment/uncomment
Selection
- Shift + Arrow Keys - Select text
- Ctrl+A - Select all
- Mouse drag - Select text with mouse
- Mouse double click - Select word with mouse
- Mouse triple click - Select line with mouse
Clipboard
- Ctrl+C - Copy selected text
- Ctrl+V - Paste from clipboard
- Ctrl+X - Cut selected text
History
- Ctrl+Z - Undo
- Ctrl+Y - Redo
Themes
The editor comes with built-in themes:
vesper- Dark theme default- Custom themes can be created by providing color mappings
let custom_theme = vec!;
let editor = new;
Architecture
The editor is built with several key components:
- Editor - Main widget that handles rendering and input
- Code - Text buffer with Tree-sitter integration for syntax highlighting
- History - Undo/redo functionality with edit tracking
- Selection - Text selection state management
- Theme - Color scheme management
Dependencies
ratatui- Terminal UI frameworktree-sitter- Syntax highlighting parserropey- Efficient text buffercrossterm- Cross-platform terminal manipulationarboard- Clipboard accessunicode-width,unicode-segmentation- Unicode text width calculation
Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on top of the excellent Ratatui TUI framework
- Syntax highlighting powered by Tree-sitter
- Awesome list of ratatui crates and applications awesome-ratatui