Skip to content

Commit 4435291

Browse files
committed
Initial commit
0 parents  commit 4435291

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Matthias Vogelgesang <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

doc/move.txt

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
*move.txt* Moving lines and selections up and even down
2+
3+
Author: Matthias Vogelgesang <github.com/matze>
4+
License: Same terms as Vim itself (see |move-license|)
5+
6+
===============================================================================
7+
Contents *move-contents*
8+
9+
1. Usage..................................|move-usage|
10+
2. Mappings...............................|move-mappings|
11+
3. License................................|move-license|
12+
13+
===============================================================================
14+
1. Usage *move-usage*
15+
16+
The move plugin is used to move lines and visual selections up and down by
17+
wrapping the :move command.
18+
19+
===============================================================================
20+
2. Mappings *move-mappings*
21+
22+
To enable custom key maps you must disable the automatic key maps with >
23+
24+
let g:move_map_keys = 0
25+
26+
-------------------------------------------------------------------------------
27+
2.1 <Plug>MoveBlockDown
28+
29+
Move selected block down by one line.
30+
31+
Default: vmap <C-j> <Plug>MoveBlockDown
32+
33+
-------------------------------------------------------------------------------
34+
2.2 <Plug>MoveBlockUp
35+
36+
Move selected block up by one line.
37+
38+
Default: vmap <C-k> <Plug>MoveBlockUp
39+
40+
-------------------------------------------------------------------------------
41+
2.3 <Plug>MoveLineDown
42+
43+
Move current down by one line.
44+
45+
Default: nmap <A-j> <Plug>MoveLineDown
46+
47+
-------------------------------------------------------------------------------
48+
2.4 <Plug>MoveLineUp
49+
50+
Move current up by one line.
51+
52+
Default: nmap <A-k> <Plug>MoveLineUp
53+
54+
55+
===============================================================================
56+
3. License *move-license*
57+
58+
This plugin is copyright by Matthias Vogelgesang and licensed under the MIT
59+
license.
60+
61+
vim:ft=help:

plugin/move.vim

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
" =============================================================================
2+
" File: plugin/move.vim
3+
" Description: Move lines and selections up and even down.
4+
" Author: Matthias Vogelgesang <github.com/matze>
5+
" Version: 0.1
6+
" =============================================================================
7+
8+
9+
if exists('loaded_move') || &cp
10+
finish
11+
endif
12+
13+
let loaded_move = 1
14+
15+
if !exists('g:move_map_keys')
16+
let g:move_map_keys = 1
17+
endif
18+
19+
function! s:ResetCursor()
20+
normal! gv
21+
normal! ^
22+
endfunction
23+
24+
function! s:MoveBlockDown() range
25+
let next_line = a:lastline + 1
26+
27+
if next_line > line('$')
28+
call s:ResetCursor()
29+
return
30+
endif
31+
32+
execute a:firstline "," a:lastline "m " next_line
33+
call s:ResetCursor()
34+
endfunction
35+
36+
function! s:MoveBlockUp() range
37+
let prev_line = a:firstline - 2
38+
39+
if prev_line < 0
40+
call s:ResetCursor()
41+
return
42+
endif
43+
44+
execute a:firstline "," a:lastline "m " prev_line
45+
call s:ResetCursor()
46+
endfunction
47+
48+
function! s:MoveLineUp()
49+
if line('.') == line('0')
50+
return
51+
endif
52+
execute 'm-2'
53+
endfunction
54+
55+
function! s:MoveLineDown()
56+
if line('.') == line('0')
57+
return
58+
endif
59+
execute 'm+1'
60+
endfunction
61+
62+
vnoremap <silent> <Plug>MoveBlockDown :call <SID>MoveBlockDown()<CR>
63+
vnoremap <silent> <Plug>MoveBlockUp :call <SID>MoveBlockUp()<CR>
64+
nnoremap <silent> <Plug>MoveLineDown :call <SID>MoveLineDown()<CR>
65+
nnoremap <silent> <Plug>MoveLineUp :call <SID>MoveLineUp()<CR>
66+
67+
if g:move_map_keys
68+
vmap <C-j> <Plug>MoveBlockDown
69+
vmap <C-k> <Plug>MoveBlockUp
70+
nmap <A-j> <Plug>MoveLineDown
71+
nmap <A-k> <Plug>MoveLineDown
72+
endif

0 commit comments

Comments
 (0)