vim-surround icon indicating copy to clipboard operation
vim-surround copied to clipboard

Request: Delete surrounding function

Open wellle opened this issue 10 years ago • 7 comments

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!

wellle avatar Feb 01 '15 00:02 wellle

+1 for this feature. I see there is wrap implementation with ysiwf. Would also be very useful if we could delete surrounding function.

imomaliev avatar Jul 18 '16 12:07 imomaliev

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?

wellle avatar Mar 01 '18 09:03 wellle

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.

romgrk avatar Mar 01 '18 19:03 romgrk

I'll make an attempt to implement this, if no one else has already begun?

philipjhj avatar Mar 04 '19 12:03 philipjhj

@philipjhj there already is https://github.com/tpope/vim-surround/pull/118

imomaliev avatar Mar 04 '19 13:03 imomaliev

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.

wellle avatar Mar 22 '20 12:03 wellle

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.

Matt-A-Bennett avatar Jan 21 '22 09:01 Matt-A-Bennett