From: Iain Patterson Date: Wed, 2 Oct 2013 16:35:25 +0000 (+0100) Subject: Move plugin. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=cf2c0d793fbcc5129774a7fe5dcf3297fd4d6239;p=profile.git Move plugin. Move lines or blocks with alt+d/j/k/u. --- diff --git a/.vim/doc/move.txt b/.vim/doc/move.txt new file mode 100644 index 0000000..48a557b --- /dev/null +++ b/.vim/doc/move.txt @@ -0,0 +1,115 @@ +*move.txt* Moving lines and selections up and even down + +Author: Matthias Vogelgesang +License: MIT (see |move-license|) + +=============================================================================== +Contents *move-contents* + + 1. Usage..................................|move-usage| + 2. Mappings...............................|move-mappings| + 3. License................................|move-license| + 4. Changelog..............................|move-changelog| + +=============================================================================== +1. Usage *move-usage* + +The move plugin is used to move lines and visual selections up and down by +wrapping the :move command. + +=============================================================================== +2. Mappings *move-mappings* + +To enable custom key maps you must disable the automatic key maps with > + + let g:move_map_keys = 0 + +The plugin provide finger-friendly mappings to move text around by using +keys. Your can specify the key modifier that uses in key bindings with > + + let g:move_key_modifier = 'M' + +All mappings can be prefixed with a {count} and will move {count} steps +instead of one. + +------------------------------------------------------------------------------- +2.1 MoveBlockDown + +Move selected block down by one line. + +Default: vmap MoveBlockDown + +------------------------------------------------------------------------------- +2.2 MoveBlockUp + +Move selected block up by one line. + +Default: vmap MoveBlockUp + +------------------------------------------------------------------------------- +2.3 MoveLineDown + +Move current line down by one. + +Default: nmap MoveLineDown + +------------------------------------------------------------------------------- +2.4 MoveLineUp + +Move current line up by one. + +Default: nmap MoveLineUp + +------------------------------------------------------------------------------- +2.5 MoveBlockHalfPageDown + +Move selected block down by half a page size. + +Default: not mapped + +------------------------------------------------------------------------------- +2.6 MoveBlockHalfPageUp + +Move selected block up by half a page size. + +Default: not mapped + +------------------------------------------------------------------------------- +2.7 MoveLineHalfPageDown + +Move current line down by half a page size. + +Default: not mapped + +------------------------------------------------------------------------------- +2.7 MoveLineHalfPageUp + +Move current line up by half a page size. + +Default: not mapped + +=============================================================================== +3. License *move-license* + +This plugin is copyright by Matthias Vogelgesang and licensed under the MIT +license. + +=============================================================================== +3. Changelog *move-changelog* + +v1.3-dev + * Silence :move commands to avoid first-time errors on read-only files. + +v1.2 + * Released on 08/14/13 + * Add key modifier for bindings (@vitalk) + * Use and in normal and visual mode (@vitalk) + * Add Move{Block,Line}HalfPage{Up,Down} to move text in larger + increments. +v1.1 + * Released on 08/10/13 + * Minor bug fixes (helptags, mapping, docs) +v1.0 + * Released on 08/10/13 + +vim:ft=help: diff --git a/.vim/plugin/move.vim b/.vim/plugin/move.vim new file mode 100644 index 0000000..150a170 --- /dev/null +++ b/.vim/plugin/move.vim @@ -0,0 +1,141 @@ +" ============================================================================= +" File: plugin/move.vim +" Description: Move lines and selections up and even down. +" Author: Matthias Vogelgesang +" ============================================================================= + +if exists('loaded_move') || &cp + finish +endif + +let loaded_move = 1 + +if !exists('g:move_map_keys') + let g:move_map_keys = 1 +endif + +if !exists('g:move_key_modifier') + let g:move_key_modifier = 'A' +endif + +function! s:ResetCursor() + normal! gv=gv^ +endfunction + +function! s:MoveBlockDown(start, end, count) + let next_line = a:end + a:count + + if v:count > 0 + let next_line = next_line + v:count - 1 + endif + + if next_line > line('$') + call s:ResetCursor() + return + endif + + execute "silent" a:start "," a:end "m " next_line + call s:ResetCursor() +endfunction + +function! s:MoveBlockUp(start, end, count) + let prev_line = a:start - a:count - 1 + + if v:count > 0 + let prev_line = prev_line - v:count + 1 + endif + + if prev_line < 0 + call s:ResetCursor() + return + endif + + execute "silent" a:start "," a:end "m " prev_line + call s:ResetCursor() +endfunction + +function! s:MoveLineUp(count) range + let distance = a:count + 1 + + if v:count > 0 + let distance = distance + v:count - 1 + endif + + if (line('.') - distance) < 0 + execute 'silent m 0' + normal! == + return + endif + + execute 'silent m-' . distance + + normal! == +endfunction + +function! s:MoveLineDown(count) range + let distance = a:count + + if v:count > 0 + let distance = distance + v:count - 1 + endif + + if (line('.') + distance) > line('$') + execute 'silent m $' + normal! == + return + endif + + execute 'silent m+' . distance + normal! == +endfunction + +function! s:MoveBlockOneLineUp() range + call s:MoveBlockUp(a:firstline, a:lastline, 1) +endfunction + +function! s:MoveBlockOneLineDown() range + call s:MoveBlockDown(a:firstline, a:lastline, 1) +endfunction + +function! s:MoveBlockHalfPageUp() range + let distance = winheight('.') / 2 + call s:MoveBlockUp(a:firstline, a:lastline, distance) +endfunction + +function! s:MoveBlockHalfPageDown() range + let distance = winheight('.') / 2 + call s:MoveBlockDown(a:firstline, a:lastline, distance) +endfunction + +function! s:MoveLineHalfPageUp() range + let distance = winheight('.') / 2 + call s:MoveLineUp(distance) +endfunction + +function! s:MoveLineHalfPageDown() range + let distance = winheight('.') / 2 + call s:MoveLineDown(distance) +endfunction + +function! s:MoveKey(key) + return '<' . g:move_key_modifier . '-' . a:key . '>' +endfunction + + +vnoremap MoveBlockDown :call MoveBlockOneLineDown() +vnoremap MoveBlockUp :call MoveBlockOneLineUp() +vnoremap MoveBlockHalfPageDown :call MoveBlockHalfPageDown() +vnoremap MoveBlockHalfPageUp :call MoveBlockHalfPageUp() + +nnoremap MoveLineDown :call MoveLineDown(1) +nnoremap MoveLineUp :call MoveLineUp(1) +nnoremap MoveLineHalfPageDown :call MoveLineHalfPageDown() +nnoremap MoveLineHalfPageUp :call MoveLineHalfPageUp() + + +if g:move_map_keys + execute 'vmap' s:MoveKey('j') 'MoveBlockDown' + execute 'vmap' s:MoveKey('k') 'MoveBlockUp' + execute 'nmap' s:MoveKey('j') 'MoveLineDown' + execute 'nmap' s:MoveKey('k') 'MoveLineUp' +endif diff --git a/.vimrc b/.vimrc index 19d9e77..18e34fa 100644 --- a/.vimrc +++ b/.vimrc @@ -1070,6 +1070,12 @@ if has("autocmd") endif endif "}}}1 +" move. +nmap MoveLineHalfPageUp +nmap MoveLineHalfPageDown +vmap MoveBlockHalfPageUp +vmap MoveBlockHalfPageDown + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Handle options only available in Vim 7 and above. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""