zed icon indicating copy to clipboard operation
zed copied to clipboard

Vim substitution command should work if c or n flags are used

Open lsparrish opened this issue 10 months ago • 6 comments

Check for existing issues

  • [x] Completed

Describe the bug / provide steps to reproduce it

Currently :s/foo/bar replaces foofoo with barbar. There is code to override this if :s/foo/bar/n or :s/foo/bar/c are used, however it is not executed. The result is that these flags cause the command to do nothing.

Zed Version and System Specs

In Zed, create a buffer with multiple cases of the same word on the same line. Example: foofoo. Enable vim mode. Then type :s/foo/bar/c Nothing occurs. The same happens if you type :s/foo/bar/n Note: The normal vim behavior is to only replace one occurrence unless /g is used. The behavior in zed is different by design and /g is not needed, but should be possible to override with either of these options.

If applicable, add screenshots or screencasts of the incorrect state / behavior

No response

If applicable, attach your Zed.log file to this issue.

No response

lsparrish avatar Jan 19 '25 03:01 lsparrish

I mentioned this on the PR, but just to make sure it's visible:

  • I think in Vim, /n does no replacements, it just shows the count. In zed we should treat this the same as a search and ignore the replace
  • /c asks you to confirm before each replacement. I think we should "emulate" this by focusing the replace editor so you can mash <enter> to do replacements.

This will also get a lot better once we have command palette history

ConradIrwin avatar Jan 29 '25 03:01 ConradIrwin

Hi there! 👋 We're working to clean up our issue tracker by closing older issues that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and we will keep it open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, we'll close it in 7 days. Thanks for your help!

github-actions[bot] avatar Jun 04 '25 07:06 github-actions[bot]

Still relevant—I miss /c, and single replace without /g.

rbardini avatar Jun 04 '25 10:06 rbardini

/g was implemented a few months ago!

I think /n kind of works right too (it just highlights things, but doesn't move the cursor).

/c needs some work to make keyboard shortcuts right.

ConradIrwin avatar Jun 04 '25 15:06 ConradIrwin

/g was implemented a few months ago!

@ConradIrwin Is it possible to replace only the next occurrence when omitting /g?

rbardini avatar Jun 04 '25 18:06 rbardini

Yes, https://github.com/zed-industries/zed/pull/28138 added that. Are you seeing something different?

ConradIrwin avatar Jun 04 '25 19:06 ConradIrwin

Ahhh you're right, I was using :%s instead of :s, never mind 😅 Looking forward to /c though!

rbardini avatar Jun 05 '25 13:06 rbardini

Fixed it 🦀

warp-records avatar Jul 07 '25 16:07 warp-records