Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim : swap 2 distant lines in one move

Tags:

vim

(NB : my first post)

In a Vim file, how may I swap - in one move - line 15 and line 33 (e.g.) ?

like image 499
ThG Avatar asked Dec 05 '22 02:12

ThG


2 Answers

Fastest way is to move lines:

:33m 15|15m 33

Move line 33 below line 15, then moves line 15 below line 33.

It's best to do it 'move high-number below low-number' first, otherwise you have to adjust offsets:

:15m 33|32m 14

like image 190
searlea Avatar answered Feb 08 '23 22:02

searlea


Two ways I can think of. With Vim there are probably more!

:33 | delete | 15 | put | 15 | delete | 32 | put

...or...

13ggdd15ggPjdd33ggP

...which is fewer keystrokes but a little less comprehensible when written down!

like image 38
Johnsyweb Avatar answered Feb 09 '23 00:02

Johnsyweb