zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
45.73k stars 2.52k forks source link

Vim mode: add :s/search/replace command #9428

Closed dancojocaru2000 closed 2 weeks ago

dancojocaru2000 commented 5 months ago

Check for existing issues

Describe the feature

I find needing to use the GUI for find&replace to be quite unwieldy. It would be quite useful to have Vim's :s implemented. The features (some missed by other projects implementing Vim emulation) should be:

If applicable, add mockups / screenshots to help present your vision of the feature

No response

ConradIrwin commented 5 months ago

:+1: We currently support :%s/../.., (and you can use any character instead of /) but you have to use % and /g is always provided. It would be lovely to parse this more similarly to vim.

TODO:

If you'd like to pair with me on this, you can book time here: https://calendly.com/conradirwin/pairing

elyobo commented 5 months ago

Global search and replace is handy but current line and fixed number of lines replacement is extremely useful too (the range parsing @ConradIrwin mentions) πŸ‘

Edit: line parsing in general would be handy. Keeps throwing me off, e.g. for indentation like 3>> to indent the next three lines. Seems to work intermittently, e.g. 3dd works to delete the next three lines.

JosephTLyons commented 3 months ago

This is now in 0.134.0-pre.

elyobo commented 3 months ago

Awesome, thanks!

stepan-tikunov commented 3 months ago

Is the s/search/replace still not supported or is it still only in preview release? The only thing that worked for me is %s/search/replace which is not what I always want.

ConradIrwin commented 3 months ago

Currently we support % and (as of recently) 1,2s to give a line number range. What range syntax were you trying to use?

stepan-tikunov commented 3 months ago

I was trying to substitute the text that I selected in visual mode

ConradIrwin commented 3 months ago

I was trying to substitute the text that I selected in visual mode

πŸ‘ Thanks!

I'm in a bit of a pickle with what to do about '< and '> - vim always adds them to the command palette from visual mode and then complains if you do something "wrong" (like :w).

It seems like there are three options:

Any preferences?

On Mon, May 20, 2024 at 1:24 PM, Stepan Tikunov @.***> wrote:

I was trying to substitute the text that I selected in visual mode

β€” Reply to this email directly, view it on GitHub https://github.com/zed-industries/zed/issues/9428#issuecomment-2121060658, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAXAQGIH5DFQMRO4KX5HWLZDJEVJAVCNFSM6AAAAABEY6F4WWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRRGA3DANRVHA . You are receiving this because you modified the open/close state.Message ID: @.***>

stepan-tikunov commented 3 months ago

The first option seems the least preferable if our goal isn't to 100% replicate vim's behavior. There is no real functional difference between the zed-style and the hybrid options. But it seems that the zed-style option looks more intuitive from user's perspective as opposed to the hybrid way because for commands that don't rely on visual selection, those prefilled marks might confuse someone

dancojocaru2000 commented 3 months ago

I would very much prefer an indication that Zed will only perform the replace in the selection and won't mess up the entire file.

sstadick commented 3 months ago

I don't think the any of the original features here are implemented? The global find replace works, but none of the following works?

I'm not sure this should be closed yet, especially since it was a top voted issue. It's actually the single issue stopping me from using Zed at the moment (maybe I'm alone in how often I use Vim search replace on visual selections though 🀷).

rokob commented 1 month ago

Also something with the range syntax appears to be broken as well.

If I have the text

1
2
3
4
5

and I execute the command:

:2,3s/^/x/

I get the result

1
x2
x3
x4
5

If I do the same in vim I get the expected result:

1
x2
x3
4
5
rokob commented 1 month ago

I took a stab at the issue I mentioned: https://github.com/zed-industries/zed/pull/13920

smit2909 commented 1 month ago

+1 on this issue, it was very jarring to see the %s replaced every instance in file rather than just the selected lines in visual mode. This feels like a must have for a vim mode. Entering line ranges manually isn’t something I do ever in vim. Hoping this gets fixed soon!

elyobo commented 1 month ago

I never use visual mode, but I enter line ranges all the time - however it doesn't work anyway for many things, e.g. search and replace does not work on a single line or on a line range. Honestly the most frustrating thing in zed and why I sometimes jump back into real vim.

JosephTLyons commented 2 weeks ago

This should be landing in today's preview release.