Last active
December 31, 2020 11:55
-
-
Save nhuzaa/4589b48f0ccab158593ac2ff5183b283 to your computer and use it in GitHub Desktop.
Vim swap Lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" hack to swap lines | |
function! s:swap_lines(n1, n2) | |
let line1 = getline(a:n1) | |
let line2 = getline(a:n2) | |
call setline(a:n1, line2) | |
call setline(a:n2, line1) | |
endfunction | |
function! s:swap_up() | |
let n = line('.') | |
if n == 1 | |
return | |
endif | |
call s:swap_lines(n, n - 1) | |
exec n - 1 | |
endfunction | |
function! s:swap_down() | |
let n = line('.') | |
if n == line('$') | |
return | |
endif | |
call s:swap_lines(n, n + 1) | |
exec n + 1 | |
endfunction | |
noremap <silent> <s-up> :call <SID>swap_up()<CR> | |
noremap <silent> <s-down> :call <SID>swap_down()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment