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

Add surrounding function name delete/change

Open LeszekSwirski opened this issue 11 years ago • 8 comments

Adds f/F support to s:dosurround, to allow changing/deleting the name of a surrounding function call. As with t, f preserves whitespace while F removes it. For example,

Old text                  Command      New text
func(arg1, ar*g2)         dsf          arg1, arg2
func(  arg1, ar*g2  )     csf)         (  arg1, arg2  )
func(  arg1, ar*g2  )     csF)         (arg1, arg2)

LeszekSwirski avatar Dec 27 '13 23:12 LeszekSwirski

Oh I just opened #157 to request exactly what you did here.

@tpope: Do you think this could get merged? :pray:

wellle avatar Feb 01 '15 00:02 wellle

The mentioned regex [\i.]\+\s*( is not possible in vim. \i does not work inside of a collection []. This is documented in vim: see second last note in :h /collection

...
- The following translations are accepted when the 'l' flag is not
  included in 'cpoptions' {not in Vi}:
    \e  <Esc>
    \t  <Tab>
    \r  <CR>    (NOT end-of-line!)
    \b  <BS>
    \n  line break, see above |/[\n]|
    \d123   decimal number of character
    \o40    octal number of character up to 0377
    \x20    hexadecimal number of character up to 0xff
    \u20AC  hex. number of multibyte character up to 0xffff
    \U1234  hex. number of multibyte character up to 0xffffffff
  NOTE: The other backslash codes mentioned above do not work inside
  []!

Python identifiers can be defined as:

identifier ::=  (letter|"_") (letter | digit | "_")*

from https://docs.python.org/2/reference/lexical_analysis.html#identifiers

A working regex for python is: [_[:alnum:].]\+\s*(

Hotschke avatar Nov 04 '15 12:11 Hotschke

A working vim regex would be: \(\i\+\.\=\)\+\s*(

kiryph avatar Jan 25 '16 17:01 kiryph

I was about to open the same PR but found this one from a while back. Is there anything left to do here that I can help with to get it merged?

zdcthomas avatar Mar 21 '20 20:03 zdcthomas

Since this PR 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

Candidly, Surround just doesn't make the cut for things I have time to work on these days. Years of experience have taught me that blindly clicking the merge button on PRs I don't have time to audit just creates a giant mess. I'll leave this open in case my priorities shift, but until then, Surround is essentially in a feature freeze.

Sandwich has been on my radar for a while and does seem cool, even if the default s map doesn't work for me.

tpope avatar Mar 22 '20 17:03 tpope

Thanks for the update! No worries, this is totally understandable. We owe you a lot for creating all these immensely useful and influential plugins in the first place. 🙌 Take care!

wellle avatar Mar 22 '20 19: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 15:01 Matt-A-Bennett