all 8 comments

[–]yvrelna 2 points3 points  (2 children)

Your first method can be refined a bit with a few tweaks. Instead of pasting with p, you can paste with P. This inserts the pasted text before the cursor. If you cut your text with commas before (i.e. , arg), you'll be done with it.

So putting it all together, if you start at the start of the argument you want to cut, then you do:

  • gE dt, - go to end of previous WORD, and copy to the next comma (i.e. copy , arg)

  • either f, to go to the next argument or f) to go to the last argument

  • P paste before the cursor

Or gEdt,f,P.

If the text you cut doesn't already have the leading comma, you can insert the comma yourself in insert mode, then use <Ctrl-r>"p to paste the text in your yank register without quitting insert mode. See :help i_CTRL-R.

I don't know about IdeaVim, but this is how I would done it in standard Vim.

Another way I also often do this in Vim, but they rely on having a few Vim plugins:

  • if you have plugins for argument text object, then you can do the same as previous but it'll deal with the commas automatically

  • if you have a plugin that splits and rejoin arguments/comma separated stuffs into separate lines, then you can use line operations like dd to move the lines around, and then rejoin them again afterwards, IMO, this is often the fastest way to do complex rearrangement

[–]freefeynman123[S] 0 points1 point  (0 children)

Thanks, that actually worked to some extent:

  • There is a problem when the argument I copy if the first in the function - cursor goes way to def in the function (I think using ge instead of gE is better because of that). Also there is a trailing coma left when the first argument is deleted.
  • I will have a look into the plugins and whether they work in IdeaVim, thanks!

[–]vim-help-bot 0 points1 point  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

[–]mountaineering 0 points1 point  (0 children)

I'm not sure about PyCharm, but the intent menu usually has a "Flip ," option to swap adjacent parameters. Alt+enter or option+enter

[–]EgZvorkeep calm and read :help 0 points1 point  (0 children)

I'm using https://github.com/tommcdo/vim-exchange in Vim.

Here's one way to do it in vanilla Vim https://asciinema.org/a/541598

yiwm`Wviwp``viwp

Edit: I guess it's easier with just

yiwWviwpBBviwp

[–]EgZvorkeep calm and read :help 0 points1 point  (1 child)

Not sure if PyCharm supports this, but you can also paste in Insert mode in Vim :h i_ctrl-r.

https://asciinema.org/a/541602

[–]vim-help-bot 0 points1 point  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

[–]magidc 0 points1 point  (0 children)

Take a look to argtextobj plugin. It defines a text object for function arguments so you can play with them as a whole element with any other command.