vim-surround
vim-surround copied to clipboard
Add surrounding function name delete/change
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)
Oh I just opened #157 to request exactly what you did here.
@tpope: Do you think this could get merged? :pray:
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*(
A working vim regex would be: \(\i\+\.\=\)\+\s*(
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?
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.
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.
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!
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.