Skip to content

Conversation

@aspiers
Copy link
Contributor

@aspiers aspiers commented Jan 3, 2026

Summary

Adds missing Emacs/Readline-style text editing shortcuts to the TUI (terminal) prompt input, improving text editing efficiency in the terminal.

Changes

New shortcuts

Shortcut Action
alt+u Uppercase word from cursor
alt+l Lowercase word from cursor
alt+c Capitalize word from cursor
ctrl+y Yank (paste) last killed text
ctrl+t Transpose characters (requires rebind)

User-facing behavior

Case transformations (alt+u, alt+l, alt+c)

  • When cursor is on a word character: transforms the word starting from cursor position
  • When cursor is on whitespace: transforms the next word
  • When no next word exists: transforms the previous word
  • With text selection: transforms the selected text
  • After transformation: cursor moves to end of the transformed word

Kill ring support (ctrl+y)

  • The ctrl+k, ctrl+u, ctrl+w, and alt+d delete commands now save deleted text to a kill buffer
  • ctrl+y inserts the contents of the kill buffer at the current cursor position
  • Simple single-entry buffer (full kill ring can be added later)

Transpose characters (ctrl+t)

  • Swaps the character under the cursor with the character immediately preceding it
  • At beginning of line: swaps first two characters
  • At end of line: swaps last two characters
  • Cursor advances one position to the right (unless already at end of line)

Configuration

All new shortcuts are configurable via opencode.json:

{
  "keybinds": {
    "input_lowercase_word": "alt+l",
    "input_uppercase_word": "alt+u",
    "input_capitalize_word": "alt+c",
    "input_yank": "ctrl+y",
    "input_transpose_characters": "ctrl+t"
  }
}

Note on ctrl+t conflict:
By default, ctrl+t is bound to variant_cycle (cycle model variants). To use ctrl+t for transpose characters, you can rebind, e.g.:

{
  "keybinds": {
    "variant_cycle": "<leader>v",
    "input_transpose_characters": "ctrl+t"
  }
}

Technical details

  • TUI uses OpenTUI's TextareaRenderable which has limited built-in actions
  • Implementation adds helper functions for word boundary detection matching Readline behavior
  • Tests added for word boundary detection and transformation functions

Files

  • packages/opencode/src/config/config.ts - Added keybind schema entries
  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx - Implemented shortcuts
  • packages/web/src/content/docs/keybinds.mdx - Updated documentation
  • packages/sdk/js/src/v2/gen/types.gen.ts - Regenerated from schema
  • packages/opencode/test/tui/text-transform.test.ts - Added 17 tests

@aspiers
Copy link
Contributor Author

aspiers commented Jan 3, 2026

I'm guessing the test failures are due to #6674, rather than anything to do with this PR.

@aspiers aspiers force-pushed the readline-additions branch from cc3e56b to c71c6be Compare January 5, 2026 10:16
@aspiers
Copy link
Contributor Author

aspiers commented Jan 5, 2026

Tests passing after rebase.

Without this patch, users must manually retype text to change case or
paste deleted content in the TUI prompt, and some keybindings conflict
with other TUI functions.

This is a problem because it slows down text editing and limits the
ability to customize keybindings to match user preferences.

This patch solves the problem by adding configurable shortcuts for
lowercase, uppercase, capitalize word, transpose characters, and yank
operations, along with a kill buffer for storing deleted text.
@aspiers aspiers force-pushed the readline-additions branch from c71c6be to c842ce0 Compare January 5, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant