opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(tui): add vi basic mode extension for prompt and editor

Open ryanwyler opened this issue 1 month ago • 4 comments

Summary

A modular vi mode implementation for the OpenCode TUI prompt with support for standalone editors.

Provides the vi extension for prompt but also for the Project Files Viewer and Editor https://github.com/anomalyco/opencode/pull/7017

Core Features

  • Normal/insert modes with standard vi keybindings
  • Movement: h/j/k/l, w/b/e, 0/$, G, {/}, %, g{n}g, ctrl+f/b
  • Delete: x, {n}x, dd, d{n}d, dw, d{n}w, D, d$, dG, d{n}G
  • Change: cc, c{n}c, cw, c{n}w, C, s
  • Yank: yy, y{n}y, y$, yG, y%, y{, y}
  • Paste: p/P (line-wise or character-wise)
  • Multiline: o, O, J
  • Other: r, ~, ., u, ctrl+r
  • Search: /, ?, n, N (with regex support)
  • Search operators: d/, d?, c/, c?, y/, y?

Configuration

  • prompt_vi_basic KV setting to enable/disable
  • vi_basic_clip_x KV setting for clipboard behavior
  • Toggle via command menu

Architecture

  • PromptExtension interface for modular prompt extensions
  • lineNumbers option for gutter redraw (opentui workaround)
  • Two modes: full (for standalone editors) and prompt (for prompt input)

Files Changed

File Changes
lib/vi-basic-core.ts Core vi mode logic
lib/vi-basic-extension.tsx Prompt extension wrapper
lib/prompt-extension.ts Extension interface
component/prompt/index.tsx Integration

ryanwyler avatar Jan 06 '26 02:01 ryanwyler

The following comment was made by an LLM, it may be inaccurate:

Duplicate PR Check Results for PR #7016

No duplicate PRs found.

While the search found several related PRs focused on TUI keybindings and navigation, none are duplicates of PR #7016:

Related (but distinct) PRs:

  • #6448 - feat(tui): [EXPERIMENTAL] Vim-style window system with extensible plugin views - This is a broader vim-style window system, not the specific vi mode keybinding implementation in this PR
  • #5255 - feat(tui): add ctrl+arrow word navigation in prompt - Word navigation enhancement, different scope
  • #3888 - feat: add keybindings reference dialog to TUI - Keybindings documentation, not vi mode implementation
  • #6753 - feat(keybinds): support physical keycode-based keybindings for non-English layouts - General keybinding infrastructure, not vi mode specific

PR #7016 is unique as it implements a modular vi basic mode extension with specific vi keybindings (h/j/k/l, yank, delete, change, search operators, etc.) for the prompt component. This hasn't been addressed in any other open PR.

github-actions[bot] avatar Jan 06 '26 02:01 github-actions[bot]

Enable VI prompt in Command Menu image

opencode-vi-basic-extension

ryanwyler avatar Jan 06 '26 02:01 ryanwyler

Screenshot from 2026-01-05 19-07-57

ryanwyler avatar Jan 06 '26 02:01 ryanwyler

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

github-actions[bot] avatar Jan 12 '26 00:01 github-actions[bot]

Closing PR, will use for personal use. Branch available on my fork if you want it.

ryanwyler avatar Jan 15 '26 05:01 ryanwyler