First of all I want to say that I know and use delimitmate and surround-vim.
And while they work pretty well, there is room for improvement. I'll explain what I mean.
Suppose I'm writing the code
foo = bar() # some comment
And what I need is to wrap bar function call in another function call.
foo = baz(bar()) # some comment
The best option I know right now is to use surround-vim. So suppose cursor is at the start of bar. I press v w l l shift+S shift+(
(then I type bar
, but that's not relevant).
Let's count, this is 6 key presses and two of them with Shift, which is harder than without it, right?
So I'm imagining another solution to this problem.
What if when I'm pressing (
(or some other key) the editor would detect that and propose some place to place the )
and I would choose that. The most effective way of doing that could be observed in easy-motion plugin.
The editor could mark the choices with colored letters and the user would choose by pressing letter with pressed Ctrl or something. This would be just two key presses (one with ctrl though) - 3 times less!
If such a plugin doesn't exist (and I think it doesn't) I'm willing to write one myself, but I don't know where to start.
For example, how do I detect that (
was pressed? And how do I mark choices with colored letters?
EDIT1. I know about surround's ys
mapping, and I'm using it. But let's look at how many key presses you need to make with it:
ysiWf baz <cr>
Six key presses. And with my (proposed) plugin it's still only two. Notice the fact that with my plugin you don't need to think about what motion to use, I believe it's much better because of this. But let's make things more interesting. Let's imagine I need to transform this.
foo = bar(), baz(), goo()
into this
foo = boo(bar(), baz()), goo()
So I would need to press something ys4ff bar <cr>
. It's still 6 key presses, but I would need to count parenthesis and this gets messy quite soon with more complicated expressions.
Also I believe that it's less natural to do it that way. Because I don't know about you, but at first I think about what function I need to use for wrapping and the next natural action is to type its name, not thinking about what motion I need to use to surround something.
)
could go? I think that problem is way harder than anything related to implementing it in VimScript.