-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 surround keybinds #320
Conversation
Just wondering, how do you get the text of what you typed showing there? Looks cool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks interesting but the keys looks weird. At least the key proposed here seemed inconsistent or does not work well with the current select option. What if we do
- select around tag (include the key searched)
- select inner tag (exclude the key searched)
- select only tag (only the 2 matched keys found)
Which only does select, and to change stuff we can do d
or c
or i
after select. At least with these it is more consistent and can work with existing cursors or selection.
But one issue with this model that I mention is it won't work well on html end tags since they require an extra /
.
It's screenkey :D
(I'm assuming when you say tags in the bullet points you mean surround characters like That's how I initially tried to implement it - placing selections on the surround chars seems the ideal way to do it, but I quickly ran into problems. Since the cursors placed on them are normal selections, deletion will work well, but adding and replacing will become hard. If we have a buffer like this and the
... if the user presses But if we have something like this...
... and the user tries to type
The problem is we can't magically tell if the intention is to simply add a single I agree that selections you can make with respect to surround chars which you can then manipulate with normal operations like |
Text objects for these two would be nice to have though.
HTML tag support is currently not implemented but definitely worth looking into in the future (the current implementation assumes all surround chars have a length of 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to think through the mappings but I'd probably like to use ma
and mi
for text object selection. It feels like they'll be more frequently used too.
Maybe we could consider m+
/m-
? It's a bit harder to type though.. Or ms
/mr
for "match surround"/"match remove"
After thinking through usability and looking at https://github.com/h-youhei/kakoune-surround I do think you're right in surrounding the selection but not requiring a selection on remove, it seems easier to use because you don't need to make a precise selection.
Ah, I didn't know kakoune have something similar. But one thing I am worried is what if someone wants to add/replace with multiple characters rather than one character? Do we not support surround cases like that? I see it being a good usecase like. <p>one</p>
<p>two</p>
<p>three</p> For example, adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I tested and it works with usual case, and I try breaking it with utf-8 characters but it still work.
The only case where it didn't work is.
<p *ngIf="hello < 1">w(#)orld</p>
<p *ngIf="hello < 1">w(#)orld</p>
<p *ngIf="hello < 1">w(#)orld</p>
With cursor positioned at (#)
, when I do mr<a
, it became
<p *ngIf="hello a 1">world</pa
<p *ngIf="hello a 1">world</pa
<p *ngIf="hello a 1">world</pa
Yeah, we don't support this now, but I think this may do weird cases where people have quotes within these special characters and it will break some stuff on people's code if we are not careful, especially with parts that have regex.
Just wondering, can we have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure this doesn't get merged accidentally, at the very least the gm
conflict needs resolving
@archseer the + and - variants are definitely hard to type -
@pickfire It's definitely a good and valid usecase (and a godsend when you're editing html). I'll add it in another PR since I don't want to stall this one :P
That's already implemented in this PR, it's showcased towards the end of the gif :)
Yeah that's definitely a bug. I'm thinking of a treesitter based implementation and then using the current implementation as a fallback. That would correctly identify the valid surround pairs.
Aha that seems the most ergonomic way to do it; I'll add it with the html tag editing support PR :) |
(Passing by just to say it's really cool 👏 ) |
Added documentation, changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Adds vim-surround functionality, with keybinds inspired from vim-sandwich:
ma<char>
ms<char>
- Addchar
around selectionmd<char>
- Deletechar
pairmr<from><to>
- Replacefrom
withto
Goto matching bracket (previously
m
) has been moved tomm
.TODO:
mm
changeFuture work:
vim-sandwich
like visual feedbackb
as a generic surround char finder (likeb
in vim-sandwich)Bugs
match_bracket
implementation).