curd-editor 0.4.0

A small terminal code editor with language-server support, folding and snippets
curd-editor-0.4.0 is not a library.

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:

curl -fsSL https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.sh | sh

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

cargo run -- src/main.rs

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 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
  • Lines with a problem get a red E or yellow W beside the line number; move the cursor onto the line to read the message in the status bar. The status bar also shows a count, like E:1 W:2.
  • Without a server installed, curd works as a plain editor and says so once in the status bar.
  • CURD_LSP=off curd file.rs turns servers off. CURD_LSP="my-server --stdio" curd file.rs uses 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 as fn 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:

fn main() {
    |
}

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

cargo test                # unit tests + end-to-end tests
cargo llvm-cov            # same, with a coverage report (cargo install cargo-llvm-cov)
  • Unit tests sit next to the code in src/document/tests.rs and src/editor/tests.rs.
  • End-to-end tests in tests/e2e.rs start the real curd in 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 (needs python3). To also test against the real rust-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 up
  • src/terminal.rs — raw mode, alternate screen, screen size (restored on drop)
  • src/document.rs — the text (lines), editing it, opening and saving files
  • src/editor.rs — main loop, keys, scrolling, drawing, status bar
  • src/folds.rs — finding { ... } blocks and tracking which are collapsed
  • src/snippets.rs — snippet tables per language
  • src/lsp.rs — language server client: starting servers, the wire format, requests and replies

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
  • LSP: completion
  • Syntax highlighting
  • Challenge: PageUp / PageDown
  • Save as (name a file started without one)
  • Search, undo