kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.19k stars 62 forks source link

Implement dot-repeat #6

Closed andrewferrier closed 2 years ago

andrewferrier commented 2 years ago

I noted from reddit you're already aware that dot-repeat is a potential gap in nvim-surround, and I agree this would be super-useful; this is one of the main advantages of a surround plugin in my mind for really speeding up editing. This article might be very helpful when implementing that: https://www.vikasraj.dev/blog/vim-dot-repeat.

kylechui commented 2 years ago

Hey all, it seems that adding dot-repeat for inserting delimiters wasn't as hard as I had initially thought? I would like some more people to test it out first though. I also haven't done it for changing/deleting pairs, but I'll be looking into that shortly

andrewferrier commented 2 years ago

Yep, I tested your insert-dot-repeat branch (you forgot to mention the branch name, but I figured it out ;) - it seems to work well for repeat when inserting delimiters, thanks!

kylechui commented 2 years ago

Alright I think I have a working copy of things, including with aliasing on branch implement-dot-repeat, e.g.

local str = "This is 'a sentence `with a lot of` nested strings' in it"

Putting the cursor in the word "lot" and typing dsq.. should delete all quotes from the line. Similarly, csqb.. should replace all quotes to open/close parenthesis pairs. Please test and let me know how it is!

kylechui commented 2 years ago

One bug that I've found so far is that using the visual-mode map will "break" the dot-repeat; I see the error but haven't been able to fix it (yet). Other than that this branch seems pretty stable so far

Update: I don't think I'll fix this "bug" yet (if ever), since it seems like a relatively infrequent edge case; but also because there are two places in which the dot operator gets overwritten in visual_surround function, and it seems impossible to get that information back after the fact.

kylechui commented 2 years ago

@andrewferrier I went ahead and merged the branch into main first, as there were a sizeable amount of changes + it felt more stable than main seemed to be anyhow.

andrewferrier commented 2 years ago

Yep, just did a bit of testing - the changes on main seem pretty robust! From what I can tell this is completed. Thanks!