Skip to content

vim keybindings along with normal, insert, visual, scroll mode#2713

Closed
Waishnav wants to merge 15 commits into
anomalyco:devfrom
Waishnav:vim-modes-in-opencode-tui
Closed

vim keybindings along with normal, insert, visual, scroll mode#2713
Waishnav wants to merge 15 commits into
anomalyco:devfrom
Waishnav:vim-modes-in-opencode-tui

Conversation

@Waishnav
Copy link
Copy Markdown

@Waishnav Waishnav commented Sep 20, 2025

Why

I was bored with default keybindings, despite the README of opencode says, it is created by neovim users it still did not had usable vim keybinding support and I wanted a proper vim keybinding so I can stay on the keyboard: hop between normal/insert/visual modes, page through chat history without touching the mouse.

What I touched

  • Config surface

    • Added keybinding_mode: "vim" (JS + Go structs). If you set that flag, we boot directly into vim mode; otherwise everything behaves like before.
  • Status bar

    • Gave the status component a SetMode hook and drew a little mode pill with a hint key (esc, i, v, shift+v, s). It rides next to the agent badge so you can see at a glance where you are.
  • Textarea & editor plumbing

    • Taught the textarea about visual selections (anchor/clear, line-mode, selection rendering, deletes, yanks) and added helper moves: character/word/line motions, line inserts above/below (with indent copy), replace-under-cursor, delete-under-cursor, delete-current-line, etc.
    • Wired those helpers through the chat editor interface so the TUI can drive them directly.
    • Updated selection styles so highlighted text actually looks highlighted in visual mode.
  • Messages component

    • Added lightweight viewport helpers (line up/down, sideways nudges, previous/next user message) so the scroll mode can reuse existing message navigation.
  • TUI model

    • Introduced the vim state machine (NORMAL, INSERT, VISUAL, VISUAL-LINE, SCROLL), along with per-mode handlers.
    • NORMAL mode extras:
      • Mode switches: i, a, o, O, v, shift+v, s.
      • Motions: h/j/k/l, w/b/e, 0/^/$, x, r<char>.
      • dd deletes the current line without polluting the clipboard.
      • p drops to a fresh line and pipes through the existing paste flow.
    • VISUAL / VISUAL-LINE:
      • Selections start immediately and track the cursor moves mentioned above.
      • y yanks to the clipboard and fires the “Copied to clipboard” toast.
      • d deletes the selection (no toast, no clipboard side-effect).
    • INSERT mode just takes over typing as usual; esc sends you back to NORMAL and clears any selection.
    • SCROLL mode blurs the editor and lets the message component steer (arrows, { }, etc.), with esc or i/a hopping you back into editing.
    • Hooked yank actions into the toast manager so clipboard feedback matches the rest of the app.

Testing

No automated coverage here—launch the TUI with bun dev and walk through the key paths.

Demo

Here’s a short demo video of the VIM modes in action: https://x.com/_wolf_dev/status/1972399119353405610

Mode Screenshot
NORMAL normal-mode
INSERT insert-mode
VISUAL visual-mode
VISUAL-LINE visual-line-mode
SCROLL scroll-mode

@Waishnav Waishnav changed the title vim keybindings along with normal, insert, visual etc modes vim keybindings along with normal, insert, visual, scroll mode Sep 21, 2025
@Waishnav
Copy link
Copy Markdown
Author

Waishnav commented Oct 3, 2025

@thdxr if the opentui version is going to take a while before it’s usable, could you please review this PR?

I tried the opentui branch, but it still doesn’t have any vim keybinding mode. Should I try adding vim keybindings like this to that branch instead?

@Waishnav Waishnav closed this Nov 3, 2025
@NikoKS
Copy link
Copy Markdown

NikoKS commented Dec 8, 2025

Need this feature. Any reason it is closed?

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.

3 participants