feat(editor): vim-style search & replace in the query buffer - #59
Merged
Conversation
Add `:[range]s/pattern/replacement/flags` substitute plus `/` search UX:
- Ranges: current line, `%`, `N,M`, `.`/`$` addresses, and `'<,'>`
(pressing `:` in Visual mode pre-fills the selection range).
- Flags: `g` (all per line), `i` (ignore case), `c` (interactive
y/n/a/l/q confirm with per-match highlighting).
- Rust regex patterns; replacement supports `$1`/`${name}` plus the vim
forms `\1`, `&` (whole match), `\&`. Alternate separators (`:s#a#b#`),
escaped separators, and `:s//new/` reusing the last pattern.
- `/` search now echoes `/pattern` in the bottom bar and highlights all
matches; plain `Esc` in Normal mode clears them (`:nohlsearch`).
- The whole substitution (including a full confirm session) is a single
undo step via an edtui capture snapshot.
Bump version to 0.18.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds vim-style search and replace to the query editor, plus version bump to 0.18.0.
:ssubstitute —:[range]s/pattern/replacement/flags:s/…), whole buffer (:%s/…), line addresses (:3,7s/…),./$addresses, and visual selection (:'<,'>s/…). Pressing:in Visual mode now pre-fills'<,'>.g(all matches per line),i(ignore case),c(interactive confirm).regexcrate. Replacement supports$1/${name}and the vim forms\1,&(whole match),\&(literal&). A literal$is$$.:s#a#b#), escaped separators (:s/a\/b/c/), and:s//new/reusing the last pattern.N substitutions on M lines, and a missing match reportsPattern not found: <pat>.Interactive confirm (
cflag):%s/foo/bar/gcopens a bottom-bar prompt highlighting each match:yreplace,nskip,aall,llast,q/Escstop. Matches are scanned live so column shifts after each replacement stay correct./search UXKeeps edtui's built-in search engine but adds the missing feedback: the
/patternechoes in the bottom bar while typing, all matches highlight live, and a plainEscin Normal mode clears them (:nohlsearch).Undo
The entire substitution — including a full interactive confirm session — is a single
u, via an edtui capture snapshot taken before mutation (pinned by a regression test).Implementation
src/substitute.rs(parse/translate/resolve/apply, ~25 unit tests).src/state/substitute_confirm.rs.src/action/substitute.rs; command hook insrc/command.rs; key + bottom-bar wiring insrc/event.rs/src/ui/bottom_bar.rs;:helpsection added.regexdependency.Testing
cargo fmt --check,cargo clippy, and the full suite (655 tests) all pass.gcconfirm walk, empty-pattern reuse, the not-found error, alternate separators, Visual-mode prefill + selection scoping, single-step undo, and invalid-regex errors.