-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add surrounds support for vim #9400
Add surrounds support for vim #9400
Conversation
The first question is being revised and shouldn't take much time, I'll fix it tomorrow |
I haven't looked at the code yet, but one thing that popped into my mind yesterday: would it make more sense in Zed to make surround mode work with tree-sitter and multi-cursors? As in: Or put another way: can we do something better than what Vim has by using tree-sitter and multi-cursors? Because Vim didn't have those tools, vim-surround also has some things that I always found a bit awkward, such as changing the surrounding tag. With multi-cursors it's relatively easy though: |
Lol, |
Not sure I understand correctly. Do you mean Again: I didn't look at the code yet and I also feel bad about possibly derailing you here, but I just wanted to bring my idea about "what if multi-cursors make vim-surround easier to implement?" up so that we might end up with an easier implementation that might also fit better into Zed. |
That's okay, do we need to close this pr, I really didn't use a multi-cursor to support add and change |
Not sure. What I'd propose, if you're up for it: investigate whether what I proposed is even doable and if so how much work it would be. If it turns out that it is doable and a reasonable amount of work, then we can close this PR here and try the other approach. But if there are blockers, then we can continue here. What do you think? |
I will willing to do some investigate. With multi-cursor, we only need to select the corresponding pair of symbols for each current cursor, and we can |
Okay, @ConradIrwin pointed something out to me that I should've thought of 3 comments ago: this won't work for pairs that don't have the same start/end, i.e. |
I also didn't think of this, in multi-cursor selection mode if we want to automatically enter matching parentheses e.g. we type |
@mrnugget So let's move on to this PR? I'll fix the first issue, maybe the third one I can fix as well, and then you can review the code and see the rest of the issues XD |
@weartist I think we should fix 1 and 3 as you said; 2 seems fine for now. For 4. I think it's fine to re-use BracketPair, but if you wanted to make the code a little shorter I think you could just use a rust tuple of |
Ok, let me fix 1 and 3 and then you can review code, they may have some tweaks and optimizations. After the fix, I'll take a look at the use about of BracketPair, wait me XD |
Thanks for this, some comments in line and bugs I noticed:
I also notice there is no support for HTML tags at all. I think people will need this to feel like we have support for surround.vim, but I am happy to do that as a second PR as it adds quite a bit of complexity and the non-tag version is still useful. As always happy to talk this through if you need more help. |
@ConradIrwin A little bad message, I might need to make some changes to the code, currently my deal is 'expand_selection', but I find that this can only be checked backwards, e.g. in the current case: |
@ConradIrwin I looked at
If the user enters and so on to deal The logic of |
I think we should still use the objects and not FindForward/FindBackward because they (should) handle things like we may need to change the code to operate on ranges and not selections. |
I also think that using lookup may be a bit cumbersome, and the scope of use is relatively simple, but there may be some cases where the scope of use cannot be handled well, for example, when selecting "", the subsequent spaces may be selected together, of course, we can also handle this part manually, I will try to add an extraction range instead of the selected method :) |
@ConradIrwin Submitted a new modified version, you can check if the current logic is suitable, please just look at the |
@weartist sorry for the slow reply, I was out last week!
|
Don't mind, I'm glad I'm on the right track, I'll continue the rest of the work XD |
Once #10103 is merged, you should be able to use buffer_chars_at instead, which may make it a bit easier to iterate and keep the position tracked at the same time. |
Thanks! |
@ConradIrwin I submitted the latest code, this pr does not contain the surround in visual mode, the
|
Thanks! I will test this more thoroughly tomorrow, but those limitations seem probably ok to me. |
A new problem has been discovered, if the matching parentheses are not on the current screen (e.g. after 200 lines), may need to position the cursor to the position of the symbol when manipulating |
Luckily that's a straightforward fix, pushed to your branch. Thanks for all your hard work on this! |
Woooooo! 🥳 screenshot-2024-04-09-09.31.08.mp4 |
Hope Screen.Recording.2024-04-11.at.14.26.31.mov |
@d1y unfortunately Even more unfortunately, we don't (as far as I can figure out) have enough mechanisms in place to allow you to rebind Please do open an issue for this, as it seems nice to have an option to make it work even if it's not the default. |
the
It needs to be defined for every surround type, as you can see above I have an additional keybind to use vim paste in insert mode, since I have my vim settings set to only update the system clipboard on yank. I think if you have the default vim settings, you can omit the insert mode keybinding, and replace al instances of Using
|
For #4965
There are still some minor issues:
I'm not sure which ones need to be changed in the first issue, and which ones can be revised in the future, and it seems that they can be solved
Release Notes: