Skip to content

feat: vim motion throughout codex cli - #5094

Closed
Waishnav wants to merge 8 commits into
openai:mainfrom
Waishnav:feat/vim-keybindings-with-vim-motions
Closed

Waishnav wants to merge 8 commits into
openai:mainfrom
Waishnav:feat/vim-keybindings-with-vim-motions

Conversation

@Waishnav

@Waishnav Waishnav commented Oct 11, 2025 •

Copy link
Copy Markdown

Fixes #104, #3115, and #155

Currently throughout the Codex CLI, keymaps are kinda inclined towards emac users with the usage of Ctrl for most of the actions. This PRs introduces a focused, minimal Vim keybinding mode for the Codex CLI composer, with the core motions and operators needed for prompt editing. The implementation is deliberately small in scope and localized, so it’s easy to review, reason about, and maintain. This ships a single configuration flag, keeps state inside the composer, and exposes a tiny API to let the rest of the TUI react to “Vim Normal” when needed.

Motivation
I assumed, there are many vim users like me who want's codex to have vim motion and i'm to used to vim motions in my workflow.


What’s included (foundational scope)

Modes

  • Insert ↔ Normal, plus Visual and Visual-Line selections for motion-scoped edits. Selections mirror Vim’s built-ins (v, V) conceptually, enabling apply-an-operator-to-the-selection workflows.

Core motions & edits

  • Word motions: w, b, e in Normal/Visual contexts. These follow Vim semantics (next word start, previous word start, end of word) so operators compose naturally.
  • Line edges: 0 and $ to jump to start/end of line; used with operators.
  • Delete operator (pending + motion): d with motions such as dw, d0, d$. The implementation models “operator-pending” state and resolves once a motion arrives.

Minimal app integration for a better UX

  • Transcript access while in Normal mode: t opens the transcript overlay only when the composer is in Vim Normal mode—making discovery easy for keyboard-centric users without changing default behavior for others.
  • Pager alignment: Unifies page semantics for Ctrl-D/Ctrl-U to feel consistent with Vim-style paging (removes legacy handlers that conflicted with this mental model).

Configuration (tiny surface area)

A single enum controls keybinding style across the TUI:

[tui]
keybinding_mode = "vim"   # "emacs" (default) or "vim"
  • KeybindingMode is added to config_types and threaded through Tui → composer/overlay; default remains Emacs, so behavior is unchanged unless explicitly enabled.

Design notes (maintainability first)

  • Local state, low coupling: A compact VimState { mode, pending, clipboard } sits inside the composer. Only a small helper (composer_in_vim_normal_mode()) is exposed for higher-level UI decisions (e.g., to gate transcript open on t).
  • No new global surfaces: This PR deliberately does not add slash-commands (e.g., /vim), cheatsheet views, toasts, or broader config refactors. It stays focused on the editing model; those can follow as separate, opt-in enhancements if maintainers want them. (For contrast, the other open PR introduces /vim, footer labels, a cheatsheet, and doc churn.)
  • Predictable Vim semantics: Motions and Visual selections adhere to Vim’s documented behavior so users’ muscle memory carries over.

UX overview

  • Edit flow: Press Esc to enter Normal, use motions to move/select, then apply operators (d + motion for now). Enter Insert with standard keys (e.g., i, a, etc. where applicable in this scope) and type as usual. Visual/Visual-Line allow selecting before acting.
vim-motion.mp4
  • Discoverability: In Normal mode, t brings up the transcript quickly for keyboard-first navigation. Pager scrolling mirrors Vim expectations for Ctrl-D/Ctrl-U.
transcript.mp4
  • Opt-in: Default users keep the existing Emacs-style bindings unless they set keybinding_mode = "vim".

Tests & how to try it

  • Adds unit coverage around word motions and Visual-mode behaviours; also a helper to query “in Vim Normal mode?” for integration tests. Run the TUI package tests as usual.
  • Manual: enable keybinding_mode = "vim", launch the TUI, and validate w/b/e, 0/$, dw/d0/d$, Visual/Visual-Line selections, Esc↔Insert/Normal, t for transcript, and pager Ctrl-D/Ctrl-U.

Backwards compatibility & risk

  • Default remains unchanged (Emacs mode).
  • Changes are TUI-only and mostly localized to the composer/overlay plumbing. The pager semantic update is the only behavior change users may notice; it aligns with Vim expectations and can be fine-tuned in follow-ups if needed.

Follow-ups (separate PRs can be feasable, but I don't think needed)

  • Counts & repeats (3w, 2dd), additional operators (y, c, p), and Visual-Block mode.
  • Optional runtime toggle (e.g., /vim) or mode indicator in the footer—kept out of this foundational PR to minimize surface area. (See the other PR for a reference approach if we decide to go there later.)

Implement 'w', 'b', and 'e' word motions in Vim mode and add is_vim_normal_mode() helper. Add unit tests covering visual-mode word motions and normal-mode detection. Rationale: improve Vim editing experience in the composer.
Add composer_in_vim_normal_mode() that delegates to the composer. Enables higher-level UI to gate behavior based on Vim normal mode.
Delegate composer_in_vim_normal_mode() through ChatWidget so top-level UI can check composer Vim state.
Wire the 't' key to open the transcript overlay when the composer is in Vim normal mode. Improves discoverability of transcript while using Vim bindings.
… other handlers)

Unify page semantics so Ctrl-D/Ctrl-U perform full-page scrolling. Remove Ctrl-F/Ctrl-B and Ctrl-E/Ctrl-Y handlers and hints. Update pager key hints accordingly. Rationale: simplify and align pager behaviour for Vim mode; note this may affect users relying on previous handlers.
@Waishnav Waishnav changed the title Feat/vim keybindings with vim motions feat:vim keybindings throughout codex cli Oct 11, 2025
@Waishnav Waishnav changed the title feat:vim keybindings throughout codex cli feat:vim motion throughout codex cli Oct 11, 2025
@Waishnav Waishnav changed the title feat:vim motion throughout codex cli feat: vim motion throughout codex cli Oct 11, 2025
@Waishnav
Waishnav marked this pull request as ready for review October 18, 2025 12:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Waishnav

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ylv-io

ylv-io commented Oct 19, 2025

Copy link
Copy Markdown

It be amazing to have VIM mode in Codex 🙏

@etraut-openai

Copy link
Copy Markdown
Contributor

Thanks for the contribution, and apologies for the slow response. We've received many PRs, and we don't have the bandwidth on the codex team to review all of them.

We've updated our contribution guidelines to clarify that we're currently accepting contributions for bugs and security fixes, but we're not generally accepting new features at this time. We need to make sure that all new features compose well with both existing and upcoming features and fit into our roadmap. If you would like to propose a new feature, please file or upvote an enhancement request in the issue tracker. We will generally prioritize new features based on community feedback.

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 31, 2025
@openai openai unlocked this conversation Oct 31, 2025
@alexandremahdhaoui

Copy link
Copy Markdown

@etraut-openai This was a clean PR addressing a very common feature for TUI coding agents. This is not a way to treat customers. This convinces me of cancelling my ChatGPT subscription. Migrating to Claude.

@aasullivan

Copy link
Copy Markdown

I'd love to see this in codex as well - this is my biggest missing feature / gripe with codex.

@openai openai locked and limited conversation to collaborators Dec 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vim-like input mode

5 participants