Skip to content

wstran/ocode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ocode

ocode · read and edit code in your terminal, fast.

the ocode welcome screen

Point it at a file or a folder and it opens instantly: syntax-highlighted code, a file tree, mouse and keyboard, a real system clipboard. The whole screen is your code. The only chrome is one status line at the bottom, and even that is drawn without a background so your terminal's own colours and transparency show through.

Install

brew install wstran/tap/ocode

Or build it yourself, which needs Rust 1.85+ (pure-Rust dependencies, no C compiler):

git clone https://github.com/wstran/ocode
cd ocode
cargo install --path .

Usage

ocode               # browse the current directory
ocode src/main.rs   # open a file
ocode ./project     # open a directory (file tree)
ocode --style       # change the colour scheme

ocode editing a Rust file with the file tree open

What it does

  • Fast on big files. Rope buffer, incremental highlighting, and no polling loop: it sits at roughly 0% CPU when you are not typing.
  • Mouse and keyboard. Click to place the caret, drag or Shift+click to select, wheel to scroll, click the tree to open files.
  • Real selection and clipboard. Select, then Ctrl+C/X/V and paste into any other app.
  • Real undo/redo. Word-granular, and it restores the selection with the text. "Unsaved" means the buffer actually differs from disk, not that you touched a key.
  • Watches the file. A clean buffer auto-reloads when something else writes the file; with unsaved edits it warns instead of overwriting.
  • Images and binaries. PNG/JPEG/GIF/BMP/WebP render inline in terminals that speak the kitty graphics protocol. Anything else shows a labelled hex preview instead of an error.
  • 15 themes, 119 languages out of the box, and it only ever recolours your code, never the background.

Keyboard

Ctrl is the command key, because a terminal never delivers Cmd to an application. Hold Shift with any motion to select instead of move.

Key Action
Ctrl+S Save
Ctrl+A Select all
Ctrl+C / Ctrl+X / Ctrl+V Copy / cut / paste
Ctrl+Z / Ctrl+Y Undo / redo (Ctrl+Shift+Z also redoes)
Ctrl+F Find
Ctrl+B File tree: show, focus, hide
Ctrl+R Reload from disk
Ctrl+Q Quit
Esc Step back one layer: clear the selection, else hide the tree, else open it to pick another file. Again with nothing left to do quits

Move (add Shift to select)

Move by macOS Windows / Linux
Character
Word ⌥ ←/→ Ctrl ←/→
Line
Block (to the next blank line) ⌥ ↑/↓ Ctrl ↑/↓
Line start / end Fn ←/→ Home End
File top / bottom Ctrl Home Ctrl End Ctrl Home Ctrl End
One screen Fn ↑/↓ PageUp PageDown

Edit

Key Action
any character, or paste Insert, replacing the selection if there is one
Enter New line, keeping the current indent
Backspace / Delete Delete left / right, or the selection
⌥ Delete · Ctrl Backspace Delete the word behind
⌥ Fn Delete · Ctrl Delete Delete the word ahead
Ctrl+K Delete the whole line
Ctrl+/ Comment or uncomment the line, or every line the selection covers
Tab / Shift+Tab Indent / outdent, the line or the whole selection

Tab and Ctrl+/ both work on a multi-line selection, keep the selection afterwards so you can press again, and undo in one step.

Mouse

Action Effect
Click Place the caret
Drag Select
Shift+click Extend the selection from the caret to the click
Wheel Scroll the view, leaving the caret and any selection alone
Click a file in the tree First click selects it, a second click opens it
Click a folder in the tree Expand or collapse, on the first click

Opening a file with the mouse keeps the tree open, so you can keep browsing. Opening it with Enter gives the editor the full screen. A file needs the second click because opening one is disruptive and a stray click should not do it; a folder does not, because expanding is cheap and reversible.

ocode asks the terminal for shift+click while it runs and hands it back on exit, so your terminal's own shift-selection is untouched everywhere else.

Find

find highlighting every match, with the current one selected

Ctrl+F starts with whatever you had selected as the query. Every occurrence is tinted while the bar is open, Enter jumps to the next one and selects it, so the current match stands out from the rest and Ctrl+C copies exactly what was found. Esc closes the bar and keeps the selection.

File tree

Open it with Enter from the welcome screen, or Ctrl+B from anywhere. / move, / expand and collapse, Enter or Space opens, Tab returns to the editor. It re-reads the folder as files appear and disappear.

Styles

A scheme recolours your code; your terminal background is never painted over. 15 are built in (base16-*, Solarized, Dracula, One Dark, and more). Drop a .tmTheme into ~/.config/ocode/themes/ for others. Your pick is saved the first time you launch, and ocode --style reopens the picker.

The chrome follows the theme too: gutter, tree, selection and status text are all derived from the active scheme, so switching themes recolours the whole interface, not just the code.

Languages

119 languages out of the box:

  • TypeScript (.ts/.mts/.cts). .tsx and .jsx get a JSX-aware grammar that highlights elements, attributes and embedded expressions. .mjs/.cjs open as JavaScript.
  • Schemas, config, infra: Protocol Buffers, GraphQL, TOML, .env, INI, Dockerfile, HCL/Terraform, Nix, Bicep.
  • Web3 and ZK: Solidity, Vyper, Yul, Huff, Move, Cairo, Noir, Circom, ZoKrates, Sway, Cadence, Leo, Lean, plus Tact and FunC (TON), Clarity (Stacks), Aiken (Cardano), LIGO (Tezos), Pact (Kadena), TEAL (Algorand), Scilla.
  • Mobile and desktop: Swift, Kotlin (.kt/.kts), Dart, F#, PowerShell.
  • HDL, asm, wasm: Verilog/SystemVerilog, VHDL, Assembly (NASM and AT&T), WebAssembly text (.wat/.wast).
  • Modern systems: Zig, Elixir, Julia.
  • Web supersets, mapped to their base grammar: .vue/.svelte/.astro as HTML, .scss/.sass/.less as CSS, .mdx as Markdown.

Add any .sublime-syntax grammar in ~/.config/ocode/syntaxes/.

Images and other files

Open a PNG, JPEG, GIF, BMP or WebP and it is drawn inline, scaled to fit and centred, through the kitty graphics protocol (Ghostty, Kitty). It stays visible next to the file tree, so you can click through a folder of images. Any other binary (PDF, archives, fonts) shows a labelled hex preview of its first bytes rather than failing to open.

Changes on disk

ocode watches the open file. If another program writes it, a clean buffer reloads by itself and the reload is undoable. With unsaved edits it refuses to clobber your work: the status bar warns, Ctrl+R takes the version on disk, and a second Ctrl+S keeps yours.

Terminal setup (macOS)

For word motion (⌥ ←/→) and word delete, turn on your terminal's meta key, otherwise +key just types an accented character:

  • Ghostty, Kitty, WezTerm: works out of the box
  • iTerm2: Settings, Profiles, Keys, Presets, Natural Text Editing
  • Terminal.app: Settings, Profiles, Keyboard, Use Option as Meta key

Inline images need a terminal that speaks the kitty graphics protocol (Ghostty, Kitty).

Config

Everything lives in ~/.config/ocode/: the saved theme in config, extra themes in themes/, extra grammars in syntaxes/. The pre-rename location ~/.config/opencode/ is still read, so an existing install keeps its settings.

License

MIT. Bundled themes and grammars are MIT by their authors, see the NOTICE files. Built with ratatui, crossterm, ropey, syntect, arboard and image.

About

A fast, keyboard-driven code reader & editor for your terminal — syntax highlighting, file tree, selection & system clipboard. Binary: ocode.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages