vim-surround
vim-surround copied to clipboard
Request: Delete surrounding function
Currently we have a way to surround foo
via ysiwftest
to test(foo)
.
I would like to go back from test(foo)
to foo
by typing dsf
. It just has to act like dsb
, except that it needs to also delete the word in front of the target. That would be super useful!
+1 for this feature. I see there is wrap implementation with ysiwf
. Would also be very useful if we could delete surrounding function.
I was just made aware of https://gist.github.com/romgrk/35186f3b5a71a7d89b2229b6f73e4f32 which seems to implement this perfectly. Maybe it can be added to vim-surround?
@romgrk: Would that be fine with you?
I have no problem with that. I've cleaned up a bit the gist and added comments (it was extracted from many parts of my RC files), so it should be more readable now.
I'm here if you have any questions, but mostly it piggybacks on vim-surround. The main part is s:findFunc
that handles finding the closest function call, then calling vim-surround through an uggly feedkeys(...)
. Could be made better if it had access to vim-surround internals.
It will still need to be tested in a clean environment, because maybe there are still some assumptions that I made knowing it was meant to execute in my own environment, but I've been using that for years without problems.
I'll make an attempt to implement this, if no one else has already begun?
@philipjhj there already is https://github.com/tpope/vim-surround/pull/118
Since this issue seems pretty abandoned, I just want to let you know that a similar plugin has support for deleting surrounding functions, see https://github.com/machakann/vim-sandwich/wiki/Magic-characters#function-surroundings.
I just made vim-surround-funk to do that. You can also then 'grip' some text object with the function call. So dsf
will delete the surrounding function, and then the gs
operator will 'grip' a text object. And since I included text object for a function call, you can grip one function call (using gsaf
i.e. 'grip/surround a function) with the one you just deleted.