Anyone know of any tricks in vim to easily swap two lines of code? I know that swapping adjacent lines is trivial, but let's say I wanted to swap line 23 with line 52. Is that achievable?
yes!
:23m52|51m22
then press Enter
it is also easy to write a function to do it.
My LineJuggler plugin has normal and visual mode mappings ]E
and [E
(and others, similar to the popular unimpaired plugin) to swap the current line / selection with [count]
lines below / above.
I think a :[range]Swap {range}
command would also be helpful; I'm working on that.
Edit: Here it is: LineJugglerCommands plugin.
If you have a visual selection when you paste, it will put the selection into the default buffer after pasting. So you would do 23Gdd51GVp23GP
user move
command to move lines. e.g., swap line 23 and line 52:
:23m52 | 52m23
type :help move
to get help usage of move
, it may move a range of lines :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With