Hello, (NB : my first post)
In a Vim file, how may I swap - in one move - line 15 and line 33 (e.g.) ?
Thanks in advance
ThG
Hello, (NB : my first post)
In a Vim file, how may I swap - in one move - line 15 and line 33 (e.g.) ?
Thanks in advance
ThG
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!
I'm frequently using the following:
" Tip #470 : Piet Delport & Anthony (ad_scriven)
vnoremap <silent> g" <esc>:call <sid>SwapVisualWithCut()<cr>
function! s:SwapVisualWithCut()
normal! `.``
if line(".")==line("'.") && col(".") < col("'.")
let c = col('.')
normal! gvp```]
let c = col('.') - c
normal! ``
:silent call cursor(line("."),col(".")+c)
normal! P
else
normal! gvp``P
endif
endfunction
The idea is to delete something anywhere, then go select characters elsewhere, and hit g"
to swap the delete characters with the newly selected ones.
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