AndrewRadev / sideways.vim

A Vim plugin to move function arguments (and other delimited-by-something items) left and right.
http://www.vim.org/scripts/script.php?script_id=4171
MIT License
479 stars 9 forks source link

Ability to move conditions around && and || #23

Open boris-petrov opened 6 years ago

boris-petrov commented 6 years ago

For example in Java:

if (a && b && c != null) {
...

I would like to change a && b to b && a or b && c != null to c != null && b with Sideways.

AndrewRadev commented 6 years ago

I've created a branch that supports this particular case, only for java: if-clause-support. A general solution might be possible, but it would also be tricky. For ruby in particular, I discuss the idea here: https://github.com/AndrewRadev/sideways.vim/issues/13.

A few issues:

If you give me more examples of "I'd like this to work like this", I could either tell you "this won't work for these and these reasons", or try to implement it within the framework of the plugin. That way, we could refine a useful functionality and eventually merge it to master, or give it up as unfeasible and/or come up with different solutions. For now, the branch is there, maybe try it out and see what you're missing.

boris-petrov commented 6 years ago

Ah, sorry, I didn't see that there already was an issue for that. I guess this one could be closed as duplicate.

I'm not sure I can give more examples. The ones that you came up with are enough.

I don't know how the plugin works exactly, but can't you expose a "logic_operators" setting per language (&&, || in Java, and, or in CoffeeScript, etc) and then when the user tries to swap something in an if-clause (this could also be a setting per language (if (...) in Java, if ... \n in CoffeeScript)), it would search left and right from the cursor to either a "logic_operator" or a paren and swap these... I have no idea if that makes sense at all in VimScript. I'll leave you to decide that.

Anyway, thanks for the branch. I guess it is useful enough (you could extend it also for C/C++/JavaScript as they have the same syntax) to be merged in master.

boris-petrov commented 6 years ago

Now I just noticed that I cannot live with argument text objects and tried to do the same for the conditions in an if-clause. So a "condition text object" could be a nice addition to any language.