# curd
A small terminal code editor written in Rust with `crossterm`: open a folder as a project, browse it in a file tree with git status colours, keep several files open in tabs, and get colours, errors, suggestions, hover and go-to-definition from language servers. It has undo, selection with copy and cut, search and replace in the file and across the project, markers beside the lines you changed since the last commit, and a git menu to stage, commit, switch and create branches, pull and push.
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:
```sh
curl -fsSL https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.sh | sh
```
Windows (PowerShell):
```powershell
irm https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.ps1 | iex
```
Then:
```sh
curd . # open the current folder as a project
curd src/main.rs # open one file (or several: they open in tabs)
curd # start with an empty file
```
Other ways to get it:
- With Rust installed: `cargo install curd-editor`
- By hand: download a binary from the [releases page](https://github.com/vikram5258/crud-editor/releases)
## Run
```sh
cargo run -- src/main.rs
```
## Keys
Project and files:
| Key | What it does |
|---|---|
| Ctrl+P or Alt+P | quick open: type part of a file name, Enter opens it, Esc cancels |
| Ctrl+B or Alt+B | show or hide the file tree |
| Alt+E | move between the file tree and the text (Esc also leaves the tree) |
| Arrows, Enter (in the tree) | move; Enter or Right opens a folder or file, Left closes a folder |
| Alt+. and Alt+, | next / previous tab (Ctrl+PageDown / Ctrl+PageUp also work) |
| Alt+1 ... Alt+9 | go to that tab |
| Ctrl+W or Alt+W | close the file in front (asks for a second press if it has unsaved changes) |
| Ctrl+L or Alt+L | go to a line by its number |
| Alt+S | search the whole project: type the text, Enter lists the matching lines, Enter again opens one |
| Ctrl+G or Alt+V | git menu: stage, unstage, commit, switch or create a branch, pull, push |
| Ctrl+S | save; a file with no name yet asks for one first |
| Ctrl+Q | quit (asks for a second press if any file has unsaved changes) |
Editing:
| 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 |
| PageUp / PageDown | move one screen up / down |
| Ctrl+Home / Ctrl+End | go to the start / end of the file |
| Shift+arrows, Shift+Home / End / PageUp / PageDown | select text |
| Ctrl+A | select everything |
| Ctrl+C / Ctrl+X | copy / cut the selection, or the whole line when nothing is selected |
| Ctrl+V | paste what was copied or cut |
| Tab / Shift+Tab (with lines selected) | move the selected lines one level in / out; Shift+Tab alone moves the cursor line out |
| Alt+C or Ctrl+/ | turn the cursor line or the selected lines into comments, and back |
| Alt+Up / Alt+Down | move the cursor line up / down |
| Alt+D | duplicate the cursor line |
| Ctrl+Z / Ctrl+Y | undo / redo |
| Ctrl+F or Alt+F | search: type to find, Enter or Down for the next match, Up for the one before, Esc to close |
| F3 or Alt+N | next match of the last search |
| Ctrl+R or Alt+R | replace: type what to find, Enter, type what to put there; then Enter replaces one match, Alt+A all, Down skips one |
| Ctrl+Space or Alt+/ | ask the language server for suggestions (they also appear by themselves as you type) |
| Up / Down, Tab, Esc (in the list of suggestions) | pick one, put it in, close the list |
| 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, opening the file it is in if needed |
| Tab after a trigger word | expand a snippet (see below) |
Mouse:
| Action | What it does |
|---|---|
| Click a tab / its `×` | bring that file to the front / close it (a second click if it has unsaved changes) |
| Middle click a tab | close it |
| Wheel over the tab bar | go through the tabs |
| Click a file or folder in the tree | open it / open or close the folder |
| Click in the text | put the cursor there |
| Double click in the text | select the word |
| Drag over the text | select |
| Click beside a line that starts a block (the `-` or `+` by its number) | fold or unfold the block |
| Click a line in quick open, the git menu or search results | pick it; the wheel moves the selection, a click elsewhere closes the list |
| Wheel | scroll whatever is under the pointer |
Because `curd` listens to the mouse, selecting with the terminal itself needs Shift held while dragging (Option on macOS Terminal).
Some terminals keep certain Ctrl keys for themselves (VS Code's terminal takes Ctrl+K, Ctrl+B, Ctrl+P, Ctrl+W and Ctrl+F), which is why most commands also have an Alt or function-key form.
## Projects
`curd some-folder` opens the folder as a project. `curd some-file` works out the project from the file: its git repository if it is in one, otherwise the folder it sits in. Ctrl+B shows the tree either way.
- **File tree:** folders first, then files. Folders are read only when you open them, so large projects open instantly. The tree follows the file in front, and is re-read when you save or come back to the terminal window.
- **Git status colours**, with a letter at the right edge of the tree, the same idea as VS Code:
| Colour | Letter | Meaning |
|---|---|---|
| plain | | committed and unchanged |
| yellow | `M` | modified since the last commit, not staged |
| cyan | `S` | staged with `git add`, waiting to be committed |
| green | `U` | untracked: a new file git does not know yet |
| red | `!` | merge conflict |
| dim | | ignored by `.gitignore` |
A folder takes the colour of the most pressing change inside it. The current branch is shown under the tree. The status comes from the `git` command, run in the background so it never holds up typing.
- **Change markers beside the text:** in a file that git tracks, a bar next to the line numbers shows what is different from the last commit, and it follows every key, saved or not:
| Marker | Meaning |
|---|---|
| green `▎` | a new line |
| yellow `▎` | a changed line |
| red `▁` | lines were removed below this line (`▔` at the top of the file: removed above it) |
- **Tabs:** every open file keeps its own cursor, folds and unsaved changes. The tab bar appears when two or more files are open; a `●` marks unsaved changes and a click on the `×` closes the tab.
- **Quick open (Ctrl+P):** searches every file git tracks or would track (so not `target/` or `node_modules/`). Letters can be spread out: `wsrs` finds `workspace.rs`.
## Language servers (LSP)
`curd` gets colours, errors, warnings, suggestions, 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. One server looks after all the open files of its language in a project, so opening more files does not start more servers:
| 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` |
| YAML (`.yaml`, `.yml`) | `yaml-language-server` | `npm install -g yaml-language-server` |
- **Colours:** come from two places, as in VS Code. A small built-in scanner colours keywords, strings, comments and numbers the instant a file opens and on every key, with or without a server. The server then says what each piece of code really is (function, type, macro and so on) and its colours are laid over the scanner's a moment later. They are your terminal's own sixteen colours, so they match your terminal theme. YAML has a scanner of its own: keys, quoted and plain values, numbers and words like `true`, comments, anchors, tags, `${{ ... }}` expressions, and blocks of text after `|` or `>`.
- **Underlines:** the exact code an error or warning is about is underlined. Unused code is shown faded and deprecated code struck through.
- **Suggestions (completion):** a list opens under the cursor when you start a word or type `.` or `::`, and narrows as you keep typing. Up and Down pick one, Tab puts it in, Esc closes the list. Enter always starts a new line, so the list never gets in the way of plain typing. Ctrl+Space (or Alt+/) asks for the list by hand.
- 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.
- **Undo and redo:** Ctrl+Z takes back the last step and Ctrl+Y does it again. A step is a word typed in one go, a paste, a snippet or a suggestion. Undoing back to what was saved clears the `[modified]` mark.
- **Search:** Ctrl+F (or Alt+F) asks in the status bar and jumps to the first match as you type, with every match on screen shown in reverse. Enter or Down goes to the next match, Up to the one before, wrapping round the file. It ignores case unless you type a capital letter. After Esc, F3 (or Alt+N) repeats the search.
- **Replace:** Ctrl+R (or Alt+R) asks what to find, then what to put in its place. Enter replaces the match under the cursor and moves to the next, Down skips one, Alt+A replaces every match in the file as one step to undo, Esc stops.
- **Search the project:** Alt+S asks for the text and lists every line in the project's files that holds it (files git ignores, files that are not text and files over 1 MB are skipped; the list stops at 2000 lines). Type to narrow the list, Enter opens the line.
- **Select, copy, cut, paste:** hold Shift while moving to select, or drag with the mouse. Ctrl+C copies and Ctrl+X cuts; with nothing selected they take the whole line. Typing replaces the selection. Copied text also goes to the system clipboard in terminals that support it (the "OSC 52" sequence); Ctrl+V pastes it, also into another tab.
- **Git menu:** Ctrl+G (or Alt+V) lists the git commands; type to narrow the list and press Enter. It can stage or unstage the file in front (or the one selected in the tree), stage or unstage everything, commit what is staged with a message, switch to another branch, create a branch, pull and push. The commands run in the background and the status bar says how they went, in git's own words when they fail. Switching branch and pulling ask you to save first, and afterwards open files show what is on disk. A push of a branch that was never pushed goes to `origin`. Git is never allowed to ask for a password on the editor's screen: a command that needs one fails instead, so set up a credential helper or an SSH agent.
- **Files changed elsewhere:** when you come back to the terminal, open files that another program changed are read again, unless they have unsaved changes.
- **Save as:** Ctrl+S in a file with no name asks for one in the status bar. It never overwrites a file that already exists.
- **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 every top-level block so the whole file's outline fits on screen, and unfolds everything again; a click on the `-` or `+` does one block. Blocks are `{ ... }` in most languages and indentation in Python and YAML. 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 and YAML). Typing `}` on a blank line steps back a level. One level is four spaces, or two in YAML.
- **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:
```rust
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
```sh
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 a `tests.rs` file per module, such as `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 on every push and pull request (`.github/workflows/ci.yml`):
- the tests on Linux, macOS and Windows, with a JUnit report saved on the run
- clippy, and a check that the crate packages cleanly for crates.io
- coverage, which fails under 90% of lines, with the report saved on the run
- the end-to-end test against the real `rust-analyzer`
- `cargo audit`, which fails if a dependency has a known security problem
- release builds for all five platforms
Pushing a `v*` tag runs the same checks first and only publishes a release (GitHub binaries with a `SHA256SUMS` file, then crates.io) if they pass.
## Layout
- `src/main.rs` — reads the arguments and starts everything up
- `src/workspace.rs` — the whole window: tabs, file tree, quick open, project search, the git menu, the clipboard, routing keys, mouse and language-server messages
- `src/tree.rs` — the file tree
- `src/git.rs` — git status and branches, and running git commands, all through the `git` command
- `src/finder.rs` — quick open and its fuzzy matching; the same list picks branches, git commands and search results
- `src/screen.rs` — styled rows of text, and drawing only the rows that changed
- `src/terminal.rs` — raw mode, alternate screen, mouse and focus reports, screen size (restored on drop)
- `src/document.rs` — the text (lines), editing it, opening and saving files
- `src/editor.rs` — one open file: keys, editing, scrolling, its part of the screen, status bar
- `src/history.rs` — what was typed and deleted, for undo and redo
- `src/search.rs` — finding text in the file and in the project
- `src/diff.rs` — which lines differ from the last commit, for the change markers
- `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
- `src/highlight.rs` — colours: the built-in scanner, and the server's colours kept per line and moved along as you type
## Progress
- [x] Step 1: raw mode, read keys, Ctrl+Q
- [x] Step 2: draw the screen with `~` and a welcome message
- [x] Step 3: open a file and show it (modular refactor)
- [x] Step 4: cursor movement and vertical scrolling
- [x] Step 5: typing and deleting
- [x] Step 6: save with Ctrl+S, unsaved-changes warning, new files
- [x] Status bar and horizontal scrolling
- [x] Line numbers, code folding, snippets, auto-indent, paste
- [x] LSP: diagnostics, hover, go to definition
- [x] Colours, underlines and other decorations from the language server
- [x] Built-in syntax colouring, so colours never wait for the server
- [x] Projects: file tree, tabs, quick open, git status colours, mouse
- [x] One language server shared by all open files; go to definition across files
- [x] LSP: completion
- [x] Git: changed-line markers beside the text
- [x] PageUp / PageDown, Ctrl+Home / Ctrl+End
- [x] Save as (name a file started without one)
- [x] Search, undo and redo
- [x] Search and replace, search across the project
- [x] Select text with Shift+arrows or the mouse; copy, cut, paste
- [x] Git: stage, commit, switch and create branches, pull and push from the editor
- [x] YAML: colours, folding, two-space indent, `yaml-language-server`
- [ ] Git: see the changes of a file (diff), discard changes
- [x] Indent and unindent the selected lines with Tab; comment, move and duplicate lines
- [x] Go to a line by number
- [x] Mouse: close tabs, fold from the gutter, double click, clickable lists
- [ ] Scroll the view with the wheel without moving the cursor
- [ ] More tabs than fit on screen