3

I've been using paredit.vim for editing Clojure files. It's quite successful in managing all those parentheses in a sane way. I'm looking for a similar way for editing function calls in other programming languages. Specifically I'm looking for three capabilities :

  • Changing order of function parameters by moving a parameter to left or right,
  • Deleting a parameter,
  • When one of the parameters is a function call (there is a nested list of parameters) ability to move one parameter up and down in nesting level. Or in other words, ability to move the parentheses of the inner function call left and right.

An example to the third item with paredit.vim command adapted to function arguments:

f(1, 2, g(3, 4), 5)
              ^
            cursor

Pressing <Leader>, and > turns this into

f(1, 2, g(3, 4, 5))

First two items I want can be provided by defining a function argument as a text object. vim-argumentative and a couple of other plugins I've came across provides these items by defining function parameters as text objects.

However the third item is a bit tricky. I could not find any plugin that provides this. And I could not figure out how defining function parameters as text objects might help achieving this at all.

Using paredit.vim is not an option, since paredit knows only about S-expressions of Lisp family, not comma separated function syntax.

Does anybody know how to achieve this, preferably with a plugin, or a way that can be put into a plugin?

1
  • You can probably define a macro for your third requirement using argumentative's functions. Something like this: move to the end of the next parameter and place a mark; go back; move the closing parenthesis to the mark. Sep 13, 2016 at 3:28

1 Answer 1

4

What about %%xvi,<esc>p from (almost (*)) anywhere within a function call, with my omap-param.vim.

The first % goes to the embedded open parenthesis. The second % to the closing ). I delete it, then I ask to the vi,mapping to find the current parameter, it'll select everything from the coma under the cursor to the end of the following parameter without the following ) or ,. Escape, and you'll be at the end of the parameter, here 5. Paste the closing ) and you're done.

(*) If we start on the opening bracket, we must use only one %.

EDIT: you could also program the movements, you'll need one of the two searchpair*() function to do it. The pairs to be searched are '(', ',', ')'. But beware of the corner cases.

As vim-argumentative seems to use the same mappings, depending on whether we handle corner cases in the same way, it should work as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.