curd
A tiny terminal code editor written in Rust with crossterm, built step by step as a learning project.
Package name: curd-editor (curd is taken on crates.io). Command name: curd.
Install
One command, no Rust needed. It downloads the latest release for your system.
Linux and macOS:
|
Windows (PowerShell):
irm https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.ps1 | iex
Then run curd some-file.txt.
Other ways to get it:
- With Rust installed:
cargo install curd-editor - By hand: download a binary from the releases page
Run
Keys
| Key | What it does |
|---|---|
| Typing, Enter, Tab | insert text, a new line, four spaces |
| Backspace / Delete | delete before / under the cursor (joins lines at a line edge) |
| Arrows, Home, End | move the cursor; the view scrolls in both directions |
| Ctrl+S | save |
| Alt+K or Ctrl+K | fold / unfold the block on, or around, the cursor line |
| Alt+A | fold every top-level block, or unfold everything |
| Alt+H or F2 | hover: show what the language server knows about the thing under the cursor |
| Alt+G or F12 | go to definition |
| Tab after a trigger word | expand a snippet (see below) |
| Ctrl+Q | quit (asks for a second press if there are unsaved changes) |
Some terminals keep certain Ctrl keys for themselves (VS Code's terminal takes Ctrl+K), which is why the commands above also have Alt or function-key forms.
Language servers (LSP)
curd gets colours, errors, warnings, hover and go-to-definition from the same language servers VS Code and other editors use. It starts the server for the file's type, if it is installed:
| Language | Server | Install |
|---|---|---|
| Rust | rust-analyzer |
rustup component add rust-analyzer |
| Python | pyright-langserver |
npm install -g pyright |
| JavaScript / TypeScript | typescript-language-server |
npm install -g typescript typescript-language-server |
| C / C++ | clangd |
your system's clangd package |
| Go | gopls |
go install golang.org/x/tools/gopls@latest |
- Colours: the server says what each piece of code is (keyword, function, type, string, comment and so on) and
curdcolours it. It uses your terminal's own sixteen colours, so it matches your terminal theme. How much gets coloured depends on the server:rust-analyzercolours everything, while some servers only report names and leave keywords and strings plain. - Underlines: the exact code an error or warning is about is underlined. Unused code is shown faded and deprecated code struck through.
- Lines with a problem get a red
Eor yellowWbeside the line number; move the cursor onto the line to read the message in the status bar. The status bar also shows a count, likeE:1 W:2. - Without a server installed,
curdworks as a plain editor and says so once in the status bar. CURD_LSP=off curd file.rsturns servers off.CURD_LSP="my-server --stdio" curd file.rsuses a different one.
How it works: curd runs the server as a child process and talks to it over stdin/stdout. Edits are sent as small changes (not the whole file), batched while you type, and a background thread reads the answers, so typing never waits on the server.
Code editing
- Line numbers in a column on the left.
- Folding: lines that start a block have a
-beside their line number. Alt+K (or Ctrl+K) collapses the block into one row, shown asfn main() { ... }with a+; the same key opens it again. Alt+A folds or unfolds everything. Blocks are{ ... }in most languages and indentation in Python. Folding only changes the view, never the file. - Auto-indent: Enter keeps the current indentation and adds a level after
{,(or[(and after:in Python). Typing}on a blank line steps back a level. - Paste: pasted text goes in exactly as copied, without auto-indent.
- Snippets: type a trigger word and press Tab. Which ones exist depends on the file extension:
| Language | Triggers |
|---|---|
Rust (.rs) |
fn main struct enum impl match if for while loop test tests pl |
Python (.py) |
def class if for while main try |
| JavaScript / TypeScript | fn afn if for while log |
| C / C++ | main if for while inc |
Go (.go) |
fn main if for err |
For example, in a .rs file main + Tab becomes:
curd new-file.txt starts an empty document and creates the file on the first save. The bottom row is a status bar with the file name, a [modified] marker and the cursor position.
Test
- Unit tests sit next to the code in a
tests.rsfile per module, such assrc/editor/tests.rs. - End-to-end tests in
tests/e2e.rsstart the realcurdin a pseudo-terminal, send keys and check the screen (Linux/macOS only). - The language-server tests use a small fake server,
tests/fake_lsp.py(needspython3). To also test against the realrust-analyzer:cargo test --test e2e -- --ignored.
Test files are left out of the published crate (see include in Cargo.toml).
CI runs the tests on every push and pull request and saves a JUnit test report and a coverage report as artifacts on the run. Pushing a v* tag runs the same checks first and only publishes a release (GitHub binaries, then crates.io) if they pass.
Layout
src/main.rs— starts everything upsrc/terminal.rs— raw mode, alternate screen, screen size (restored on drop)src/document.rs— the text (lines), editing it, opening and saving filessrc/editor.rs— main loop, keys, scrolling, drawing, status barsrc/folds.rs— finding{ ... }blocks and tracking which are collapsedsrc/snippets.rs— snippet tables per languagesrc/lsp.rs— language server client: starting servers, the wire format, requests and repliessrc/highlight.rs— colours from the server, kept per line and moved along as you type
Progress
- Step 1: raw mode, read keys, Ctrl+Q
- Step 2: draw the screen with
~and a welcome message - Step 3: open a file and show it (modular refactor)
- Step 4: cursor movement and vertical scrolling
- Step 5: typing and deleting
- Step 6: save with Ctrl+S, unsaved-changes warning, new files
- Status bar and horizontal scrolling
- Line numbers, code folding, snippets, auto-indent, paste
- LSP: diagnostics, hover, go to definition
- Colours, underlines and other decorations from the language server
- LSP: completion
- Challenge: PageUp / PageDown
- Save as (name a file started without one)
- Search, undo