Skip to content

RFC: :s/old/new/[gc] find-and-replace #40

Description

@garritfra

Goals

  • :s/old/new/ — replace first match in the current cell.
  • :s/old/new/g — replace all matches in the current cell.
  • :%s/old/new/g — replace all matches in every cell of the sheet.
  • '<,'>s/old/new/g — replace within the last visual range (depends on gv-style range tracking).
  • c flag — confirm each replacement interactively.

Open questions

  • Regex or literal? Vim defaults to magic regex. Suggest starting with literal substrings + later adding \V / regex variant. Less footgun, easier to test.
  • Formulas. Replace inside raw (so =A1+1=A1+2 for :s/1/2/g)? Probably yes, with the dep graph re-registering after each replacement. But — match what users expect for :%s/A1/A2/g carefully; this is not the same as a "rename column" operation and we shouldn't pretend it is.
  • Undo granularity. One undo entry per :s invocation, not per cell. Needs a begin_batch / end_batch wrapper around the existing undo stack.
  • Iteration order. Row-major. Document it.
  • Confirm prompt UX. A modal-ish prompt at the bottom: replace with new (y/n/a/q/l), mirroring vim.

Out of scope

  • Visual-block-scoped replace.
  • :s inside a recorded macro (depends on the macros RFC).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionOpen-ended design discussionenhancementNew feature or requestrfcRequest For Comment — design proposalvimVim modal editing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions