Vim plugin for switching arguments of a Python function / method between single and multi-line

I am looking for a Vim plugin that can accept a single line statement as follows:

foo = self.some_method(param1="hi", param2="there")

and turn it into this:

foo = self.some_method(
    param1="hi",
    param2="there"
)

Big bonus points if he can add a comma to the last argument, for example:

foo = self.some_method(
    param1="hi",
    param2="there",
)

And finally, I would like to be able to turn the multi-line version back into one line, but for me, just one script with one or several lines is enough. Use Jfor reconnecting to a line is fast enough for most of the time.

I'm not looking for a solution that formats like this:

foo = self.some_method(param1="hi",
                       param2="there")
+4
source share
1 answer

: splitjoin.vim. , - :

foo = self.some_method(param1="hi", param2="there", param3="again")

, gS:

foo = self.some_method(param1="hi",
        param2="there",
        param3="again")

gJ

. python dicts, lists, tuples, statements, import

+2

Source: https://habr.com/ru/post/1524763/


All Articles