0

using vim with the plugin vim-surround pretty extensively, and I am really happy with it. However, there is one replacement for witch I haven't found a nice shortcut.

The usage case, is the following. I need :

def function argument

to become (when the cursor is in the middle of the 'argument')

def function(argument)

My attempts didn't completely fulfil my need:

I have try

ysiw) => def function (argument) # I don't like the space after the function
ysaw) => def function( argument) # I don't like the space before the argument

Since, there is always a shortcut with vim, I am asking the communitity to help me satisfy my style obsession...

Raphael Pr
  • 896
  • 10
  • 28
  • 1
    I don't have vim-surround available, but the quickest I can think of would be `F xysw)` *assuming* surround can take just a motion and not only text-objects. This isn't very short or creative though. – Randy Morris Jul 23 '13 at 18:02
  • Just out of curiosity: When does that use case come up? I don't remember ever having to make such a change ... – glts Jul 23 '13 at 18:02
  • Surround leaves you on the starting parenthesis. It is very little effort to do `lx` or `hx` to remove the space. However if you do end up doing this kind of operation often then you may want to think about recording a macro or setting up a custom mapping. – Peter Rincker Jul 23 '13 at 19:11
  • @gits : ruby accepts both syntax for passing a parameter to method. However, I definitely prefer the one with parenthesis since it is (in my opinion) more clear and it can be allow to chain method. – Raphael Pr Jul 23 '13 at 19:43
  • @RandyMorris it works ! Creative or not, I'll find a shortcut for that... Thanks for your help – Raphael Pr Jul 23 '13 at 19:46
  • @PeterRincker, yes, I'll end up doing a custom mapping for this. – Raphael Pr Jul 23 '13 at 19:47

1 Answers1

1

Without vim on hand, I think that

nmap <F6> F xyse)

or

nmap <F6> ysiw)F x

should do the trick.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • This command works, but for a mysterious reason, the mapping doesn't work as expected. It seems to me that surround command (ys) cannot be added like this in a mapping... – Raphael Pr Jul 23 '13 at 19:54
  • 1
    `ys` is not a native command as it is provided by surround.vim. You will have to use `nmap` instead of `nnoremap` – Peter Rincker Jul 23 '13 at 20:18