Created
February 25, 2014 10:51
-
-
Save lleirborras/9206774 to your computer and use it in GitHub Desktop.
Vim/Mvim/Gvim/NeoVim macro to swap lines with shift-[up | down]
This file contains hidden or 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> <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