├── LICENSE
├── README.md
├── demo.gif
└── plugin
└── MvVis.vim
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2020 Jorengarenar
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 | of the Software, and to permit persons to whom the Software is furnished to do
8 | so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | 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
18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 | IN THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MvVis
2 | =====
3 |
4 | Move visually selected text
5 |
6 | 
7 |
8 | ## Installation
9 |
10 | #### [vim-plug](https://github.com/junegunn/vim-plug):
11 | ```vim
12 | Plug 'Jorengarenar/vim-MvVis'
13 | ```
14 |
15 | #### Vim's packages
16 | ```bash
17 | cd ~/.vim/pack/plugins/start
18 | git clone git://github.com/Jorengarenar/vim-MvVis.git
19 | ```
20 |
21 | ## Usage
22 |
23 | In visual mode, press CTRL and one of directional keys (H,
24 | J, K, L) to move selected text.
25 |
26 | You can also provide a number of amount of places you want to move it, e.g.
27 | to move selection three columns to the left press `3`.
28 |
29 | ## Configuration
30 |
31 | To disable default mappings set variable `g:MvVis_mappings` to `0` and define
32 | your own, e.g.:
33 | ```vim
34 | vmap H (MvVisLeft)
35 | vmap J (MvVisDown)
36 | vmap K (MvVisUp)
37 | vmap L (MvVisRight)
38 | ```
39 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jorenar/vim-MvVis/26ec4174114b18149a569b9cc454b8677caf852b/demo.gif
--------------------------------------------------------------------------------
/plugin/MvVis.vim:
--------------------------------------------------------------------------------
1 | " MvVis - move visually selected text
2 | " Maintainer: Jorengarenar
3 |
4 | if exists('g:loaded_MvVis') | finish | endif
5 | let s:cpo_save = &cpo | set cpo&vim
6 |
7 | function! s:MvVis(d) abort range
8 | let c = v:count1
9 | norm! gv
10 |
11 | let m = mode()
12 | let m = m ==# "V" ? 2 : (m ==# "v" ? 0 : 1)
13 |
14 | if a:d == 'l' && virtcol('.') == virtcol('$')-1 | return | endif
15 |
16 | let s_old = @s
17 |
18 | if m < 2
19 | let flag = virtcol('.') == virtcol('$') - (a:d == 'h' ? 1 : 2)
20 | else
21 | let flag = line('.') >= line('$') - (a:d == 'j' ? 1 : 0)
22 | endif
23 |
24 | norm! "sd
25 |
26 | let lines = split(@s, "\n")
27 | let n = len(lines) - 1
28 |
29 | if n < 0
30 | let [ @s, lines, m ] = [ "\n", "", 2 ]
31 | elseif m == 0 && n > 0
32 | let m = 2
33 | exec 'norm! uV' . n . 'j"sd'
34 | endif
35 |
36 | exec 'norm! ' . c . a:d
37 | exec 'norm! "s' . (flag ? 'p' : 'P')
38 | let @s = s_old
39 |
40 | if m == 2
41 | norm! V
42 | if n > 0 | exec "norm! " . n . "j" | endif
43 | else
44 | let lh = strchars(lines[0])-1
45 | if m == 0
46 | exec "norm! v" . (lh > 0 ? lh . "ho" : "")
47 | else
48 | exec "norm! \" . (n > 0 ? n . "j" : "") . (lh > 0 ? lh . "l" : "")
49 | endif
50 | endif
51 | endfunction
52 |
53 | vnoremap (MvVisLeft) :call MvVis('h')
54 | vnoremap (MvVisUp) :call MvVis('k')
55 | vnoremap (MvVisDown) :call MvVis('j')
56 | vnoremap (MvVisRight) :call MvVis('l')
57 |
58 | if get(g:, "MvVis_mappings", 1)
59 | vmap (MvVisLeft)
60 | vmap (MvVisDown)
61 | vmap (MvVisUp)
62 | vmap (MvVisRight)
63 | endif
64 |
65 | let g:loaded_MvVis = 1
66 | let &cpo = s:cpo_save | unlet s:cpo_save
67 |
--------------------------------------------------------------------------------