Skip to content

Instantly share code, notes, and snippets.

@demimismo
Created July 4, 2011 07:47
Show Gist options
  • Save demimismo/1063022 to your computer and use it in GitHub Desktop.
Save demimismo/1063022 to your computer and use it in GitHub Desktop.
Vim plugin 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> <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