codex icon indicating copy to clipboard operation
codex copied to clipboard

Undo / redo typing

Open aehlke opened this issue 1 year ago • 16 comments

What feature would you like to see?

Cmd-Z / Shift-Cmd-Z to undo/redo entered text in a prompt

Are you interested in implementing this feature?

No response

Additional information

No response

aehlke avatar Aug 16 '25 13:08 aehlke

Bonus: /undo and /redo commands in OpenCode (TUI) not only rewind the chat, but also revert/restore any file changes.

https://opencode.ai/docs/tui/#undo

nilswx avatar Aug 23 '25 08:08 nilswx

please implement readline/emacs style undo (C-/ or C-_) and redo (C-?) since most readline keys appear to be implemented already.

there does not appear to be any way to undo right now.

vimsux avatar Mar 21 '26 09:03 vimsux

+1 Undo/redo typing support would be very helpful, especially in terminal environments where Cmd+Z gets intercepted.

quanru avatar Apr 01 '26 05:04 quanru

Agree, sometimes it is really frustrating when you accidentally delete a line of prompt... it's completely usable right now but it'd be better to have it.

DavidAnsc avatar Apr 19 '26 18:04 DavidAnsc

Any form of undo / redo in the text editor would be fantastic!

hunterwilhelm avatar Jun 02 '26 15:06 hunterwilhelm

I just whacked the entire prompt I had written and was pissed but asked codex about it and since I'm in linux/bash and had used ctrl+K it said duh use ctrl+y. Saved me some blood pressure, passing it along, worked great.

techjoec avatar Jun 04 '26 03:06 techjoec

I just whacked the entire prompt I had written and was pissed but asked codex about it and since I'm in linux/bash and had used ctrl+K it said duh use ctrl+y. Saved me some blood pressure, passing it along, worked great.

Awesome, it works as well for ctrl-u, ctrl-c, etc.

aehlke avatar Jun 04 '26 04:06 aehlke

I have a candidate implementation of undo/redo in the TUI composer against latest released Codex CLI, so you can build your own patched Codex.

Big quality of life improvement esp. with multiple pastes. You can undo pastes even if you typed something after. It undoes Ctrl+C clear and you can keep undoing after that. So an accidental Ctrl+V, then Ctrl+C presses can still be recovered from. Ctrl+Z/Ctrl+Shift+Z on Windows, Alt+Z/Alt+Shift+Z on Unix/Mac.

Happy to open a PR or just provide an inspiration for implementation.

astral303 avatar Aug 16 '26 22:08 astral303

(updated 2026-09-03)

Final 0.153.0 released yesterday ships undo/redo for Vim mode only.

Good to see the upstream progress on undo get made. There is still some room for improvement:

  • undo/redo works in Vim mode only
  • doesn't group explicit/detected pastes, only whole Vim commands or insert sessions
  • resets around prompt acceptance/history (Ctrl+C loses undo history, up/down loses history)

astral303 avatar Sep 01 '26 05:09 astral303

Undo for non-modal uses of composer, fully integrated with Vim undo, is available as latest-release patch branch for undo support here. (You have to build Codex yourself... but then you have undo/redo!)

astral303 avatar Sep 01 '26 20:09 astral303

Undo and redo in the composer, shared with Vim u is available as a patch against the 0.166.0 release:

  • Default keys: Ctrl+Z and Ctrl+Shift+Z on Windows, Alt+Z and Alt+Shift+Z elsewhere. Rebind them with tui.keymap.composer.undo and tui.keymap.composer.redo.
  • On macOS, Command+Z and Command+Shift+Z also work when the terminal passes them through, as Ghostty does with keybind = super+z=unbind and keybind = super+shift+z=unbind.
    • Terminal.app and iTerm2 keep Command+Z for their own menus.
  • Continuous typing groups into undo steps of at most about a second, and a pause ends a step early.
  • Deletions, pastes, and Ctrl+C clears are undoable.
  • Undo restores the cursor, attached images, and large-paste placeholders.
  • A draft cleared with Ctrl+C and recalled with Up keeps its undo history.
  • Browsing earlier prompts with Up and returning with Down keeps the draft's undo history.
  • History holds the latest 1,000 steps, or up to about 16 minutes of continuous typing.

Updated 2026-10-30: patch updated to 0.166.0, with typing grouped into undo steps, Command+Z on macOS, and undo history kept across Up and Down.

astral303 avatar Sep 03 '26 16:09 astral303

A concrete data point from 0.153.4 on the terminal side of this, now that the Vim-only undo has landed.

Terminal users who remap Cmd+Z have nothing to bind it to. A common macOS setup remaps Cmd+Z at the terminal level to 0x1f (Ctrl+_), the readline undo byte — in Ghostty that is:

keybind = super+z=text:\x1f

Claude Code's composer treats 0x1f as undo. Codex drops it silently — verified by sending the raw byte into a live 0.153.4 composer: draft unchanged, no feedback.

And there is no action to remap it onto. /keymap in 0.153.4 lists 138 configurable actions; searching undo returns exactly two, both in vim_normal — Undo (u) and Redo (ctrl-r). The tui.keymap.editor.* namespace has no undo/redo entry at all. ctrl-z is not a fallback either: the keymap validator rejects it outright ("ctrl-z is reserved for suspending the terminal on Unix").

Vim mode is not a usable workaround for non-modal users. Repro on 0.153.4 with -c tui.vim_mode_default=true:

  1. Esc Esc opens the transcript/backtrack overlay; q leaves it — the composer is left in Normal mode with no prompt to say so beyond the status hint.
  2. Type hello there — h/e/l/l move the cursor, o opens a line and drops into Insert, and only there survives as text.

Two smaller costs in the same mode: backtrack needs three Esc presses instead of two (the first is consumed switching modes), and undo granularity is the whole insert session, so u wipes an entire draft rather than the last edit.

Ask: add editor.undo / editor.redo actions to the editor keymap context so non-modal users can bind them. A default in the readline family (ctrl-_ / ctrl-/) would match the emacs-style bindings the composer already implements, sidestep the reserved ctrl-z, and give terminal-level Cmd+Z remaps something real to land on.

astradevkin avatar Sep 07 '26 08:09 astradevkin

Lol, how can a text input not have a undo? What's even going on?

jwbth avatar Oct 08 '26 13:10 jwbth

+1 from Windows (codex-cli 0.162.1). I'd like undo/redo in the default (non-Vim) composer, bindable through [tui.keymap], e.g. editor.undo = "ctrl-z" / editor.redo = "ctrl-y".

Right now undo / redo exist only in vim_normal, so they can't be bound in the regular composer. On Windows there is no SIGTSTP, so Ctrl+Z is free in the TUI. (Ctrl+Y is currently yank, so redo would need to be configurable rather than hard-coded.)

TetsuyaOYA avatar Oct 15 '26 23:10 TetsuyaOYA

Please prioritise proper undo/redo in the default Codex CLI prompt editor. This is a basic editing capability, and its absence makes composing and revising long prompts unnecessarily frustrating.

On macOS, the expected behaviour is Command-Z to undo and Command-Shift-Z to redo, without switching editing modes. Consecutive typing should form sensible groups; deletions, clears and pastes should be undoable; restoring an edit should also restore the cursor. History should cover the current unsent draft, including long prompts.

Testing Claude Code 2.1.312 confirmed grouped prompt undo and recovery after Ctrl+U deletes a sentence. That is the undo experience I want in Codex, alongside proper redo. Codex 0.165.0’s ordinary composer still lacks those actions. Ctrl+Y’s recovery of the latest deleted text is useful, but does not replace edit history.

This should ship in the official CLI. Maintaining a fork or adopting Vim mode is not a reasonable requirement for everyday prompt editing.

astradevkin avatar Oct 29 '26 00:10 astradevkin

This will be included in an upcoming release. Apologies that it took us so long to get to this one.

etraut-openai avatar Nov 17 '26 02:11 etraut-openai