Last active
July 13, 2016 17:16
-
-
Save vitormil/830d47ba2bcac3655547faa7a0850c41 to your computer and use it in GitHub Desktop.
~/.vim/plugin/swap_lines.vim
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
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> <c-s-up> :call <SID>swap_up()<CR> | |
noremap <silent> <c-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