├── LICENSE
├── README.markdown
├── autoload
└── wheel.vim
├── plugin
└── wheel.vim
└── screenshots
├── demo-text.txt
├── demo.txt
└── demo2.gif
/LICENSE:
--------------------------------------------------------------------------------
1 | License: The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Reed Esau
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
24 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # vim-wheel
2 |
3 | > Screen-anchored cursor movement for Vim
4 |
5 |
6 |
7 | - - -
8 | 
9 | - - -
10 |
11 | # Features
12 |
13 | This plugin merges the standard cursor movement of `j` and `k` with the
14 | scrolling of `` and `` to produce a new screen-anchored
15 | cursor movement. This roughly emulates movement when using a trackpad or
16 | scroll wheel.
17 |
18 | * By default, two keys are mapped: `` (like `j`) moves towards the
19 | end of buffer and `` (like `k`) move towards its beginning
20 | * Movement is tied to trackpad/scroll wheel for ‘natural’ scrolling
21 | * Due to Vim’s inherent jumpiness with `wrap` enabled, you have option to
22 | degrade to `gj` and `gk` (more details below)
23 | * Supports Visual selection
24 | * Pure Vimscript with no dependencies
25 |
26 | ## Installation
27 |
28 | You can install using your favorite Vim package manager. (E.g.,
29 | [Pathogen][pathogen], [Vundle][vundle], or [Plug][plug].) If you are using
30 | a recent version of vim or neovim, you can also use native package
31 | support. (See [:help packages][packages].)
32 |
33 | [pathogen]: https://github.com/tpope/vim-pathogen
34 | [vundle]: https://github.com/VundleVim/Vundle.vim
35 | [plug]: https://github.com/junegunn/vim-plug
36 | [packages]: https://vimhelp.org/repeat.txt.html#packages
37 |
38 | ## Configuration
39 |
40 | You can change the behavior of this plugin in your `.vimrc`:
41 |
42 | For instance, the default mappings of:
43 |
44 | ```vim
45 | let g:wheel#map#up = ''
46 | let g:wheel#map#down = ''
47 | ```
48 |
49 | ...can be changed to use the Command key in MacVim:
50 |
51 | ```vim
52 | let g:wheel#map#up = ''
53 | let g:wheel#map#down = ''
54 | ```
55 |
56 | If you have any existing mappings to `` or ``, they will be
57 | preserved.
58 |
59 | ### Trackpad/Scroll wheel behavior
60 |
61 | By default the scroll behavior of the mouse will reflect this new
62 | behavior. You can disable in your `.vimrc` if not desired.
63 |
64 | * Natural - content tracks finger movement on trackpad
65 | * Reverse - swiping down moves content up
66 |
67 | ```vim
68 | let g:wheel#map#mouse = 1 " 1=natural, 0=disable, -1=reverse
69 | ```
70 |
71 | ### End of buffer threshold
72 |
73 | _wheel_’s scrolling will cease when cursor nears the start or end of the
74 | buffer, degrading to `gj` and `gk`. You can adjust this threshold in your
75 | `.vimrc`:
76 |
77 | ```vim
78 | let g:wheel#line#threshold = 5 " lines from start or end
79 | ```
80 |
81 | ### Behavior with wrap
82 |
83 | With large blocks of wrapped text, Vim’s native scrolling with `CTRL-E`
84 | and `CTRL-Y` can be jumpy. _wheel_ inherits this behavior, unfortunately.
85 | If you would prefer that _wheel_ degrade to `gj` and `gk` when `wrap` is on,
86 | you can disable the anchored scrolling in your `.vimrc`:
87 |
88 | ```
89 | let g:wheel#scroll_on_wrap = 1 " 0=disable, 1=enable (default)
90 | ```
91 |
92 | ## See also
93 |
94 | If you find this plugin useful, check out these others originally by
95 | [@reedes][re]:
96 |
97 | * [vim-colors-pencil][cp] - color scheme for Vim inspired by IA Writer
98 | * [vim-lexical][lx] - building on Vim’s spell-check and thesaurus/dictionary completion
99 | * [vim-litecorrect][lc] - lightweight auto-correction for Vim
100 | * [vim-pencil][pn] - Rethinking Vim as a tool for writers
101 | * [vim-textobj-quote][qu] - extends Vim to support typographic (‘curly’) quotes
102 | * [vim-textobj-sentence][ts] - improving on Vim's native sentence motion command
103 | * [vim-thematic][th] - modify Vim’s appearance to suit your task and environment
104 | * [vim-wordy][wo] - uncovering usage problems in writing
105 | * [vim-wordchipper][wc] - power tool for shredding text in Insert mode
106 |
107 | [re]: https://github.com/reedes
108 | [cp]: https://github.com/preservim/vim-colors-pencil
109 | [pn]: https://github.com/preservim/vim-pencil
110 | [lx]: https://github.com/preservim/vim-lexical
111 | [lc]: https://github.com/preservim/vim-litecorrect
112 | [qu]: https://github.com/preservim/vim-textobj-quote
113 | [ts]: https://github.com/preservim/vim-textobj-sentence
114 | [th]: https://github.com/preservim/vim-thematic
115 | [wo]: https://github.com/preservim/vim-wordy
116 | [wc]: https://github.com/preservim/vim-wordchipper
117 |
118 | ## Future development
119 |
120 | There’s an experimental horizontal scrolling movement hidden within for
121 | those who wish to try it out.
122 |
123 | If you’ve spotted a problem or have an idea on improving this plugin,
124 | please post it to the [GitHub project issue page][issues].
125 |
126 | [issues]: https://github.com/preservim/vim-wheel/issues
127 |
128 |
--------------------------------------------------------------------------------
/autoload/wheel.vim:
--------------------------------------------------------------------------------
1 | " ============================================================================
2 | " File: wheel.vim
3 | " Description: autoload functions for vim-wheel plugin
4 | " Maintainer: preservim
5 | " Created: February 01, 2014
6 | " License: The MIT License (MIT)
7 | " ============================================================================
8 |
9 | if &cp || exists('g:wheel#autoloaded') | fini | en
10 |
11 | fu! wheel#VScroll(cmd, visual)
12 | " cmd: 0=up 1=down
13 | let l:threshold = max([&scrolloff, g:wheel#line#threshold])
14 | let l:ln = line('.')
15 | let l:degrade = &wrap && !g:wheel#scroll_on_wrap
16 | if a:visual ==# ''
17 | if a:cmd
18 | if l:degrade || l:ln <= l:threshold
19 | exe "sil norm! gj"
20 | el
21 | exe "sil norm! gj\"
22 | en
23 | el
24 | if l:degrade || (line('$') - l:ln) < l:threshold
25 | exe "sil norm! gk"
26 | el
27 | exe "sil norm! gk\"
28 | en
29 | en
30 | el " some kind of visual
31 | if a:cmd
32 | if l:degrade
33 | exe "sil norm! gvgj"
34 | el
35 | exe "sil norm! gvgj\"
36 | en
37 | el
38 | if l:degrade
39 | exe "sil norm! gvgk"
40 | el
41 | exe "sil norm! gvgk\"
42 | en
43 | en
44 | en
45 | endf
46 |
47 | fu! wheel#HScroll(cmd, visual)
48 | " cmd: 0=left 1=right
49 | if a:visual ==# ''
50 | if &wrap
51 | if a:cmd
52 | exe "sil norm! l"
53 | el
54 | exe "sil norm! h"
55 | en
56 | el
57 | let l:c = col('.')
58 | let l:e = col('$')
59 | if a:cmd
60 | if l:c <# (l:e - &sidescrolloff - 1)
61 | exe "sil norm! zll"
62 | elsei l:c <# (l:e - 1)
63 | exe "sil norm! l"
64 | en
65 | elsei l:c ># &sidescrolloff
66 | exe "sil norm! zhh"
67 | elsei l:c ># 1
68 | exe "sil norm! h"
69 | en
70 | en
71 | el " some kind of visual
72 | if &wrap
73 | if a:cmd
74 | exe "sil norm! gvl"
75 | el
76 | exe "sil norm! gvh"
77 | en
78 | el
79 | if a:cmd
80 | exe "sil norm! gvzll"
81 | el
82 | exe "sil norm! gvzhh"
83 | en
84 | en
85 | en
86 | endf
87 |
88 | let g:wheel#autoloaded = 1
89 |
--------------------------------------------------------------------------------
/plugin/wheel.vim:
--------------------------------------------------------------------------------
1 | " ============================================================================
2 | " File: wheel.vim
3 | " Description: vim-wheel plugin
4 | " Maintainer: preservim
5 | " Created: January 30, 2014
6 | " License: The MIT License (MIT)
7 | " ============================================================================
8 |
9 | if &cp || exists('g:wheel#loaded') | finish | endif
10 |
11 | " Save 'cpoptions' and set Vim default to enable line continuations.
12 | let s:save_cpo = &cpo
13 | set cpo&vim
14 |
15 | if !exists('g:wheel#line#threshold')
16 | " how close to begin/end of file to stop behavior
17 | " a larger scrolloff will automatically increase this threshold
18 | let g:wheel#line#threshold = 5
19 | endif
20 |
21 | if !exists('g:wheel#scroll_on_wrap')
22 | let g:wheel#scroll_on_wrap = 1 " 0=disable, 1=enable (def)
23 | endif
24 |
25 | if !exists('g:wheel#map#mouse')
26 | let g:wheel#map#mouse = 1 " 1=natural, 0=disable, -1=reverse
27 | endif
28 |
29 | if !exists('g:wheel#map#up')
30 | if empty(maparg('', 'n'))
31 | let g:wheel#map#up = ''
32 | else
33 | let g:wheel#map#up = ''
34 | en
35 | endif
36 | if !exists('g:wheel#map#down')
37 | if empty(maparg('', 'n'))
38 | let g:wheel#map#down = ''
39 | else
40 | let g:wheel#map#down = ''
41 | en
42 | endif
43 |
44 | if !exists('g:wheel#map#left')
45 | let g:wheel#map#left = '' " CTRL-H
46 | endif
47 | if !exists('g:wheel#map#right')
48 | let g:wheel#map#right = '' " CTRL-L
49 | endif
50 |
51 | nnoremap (WheelUp) :call wheel#VScroll(0, '')
52 | vnoremap (WheelUp) :call wheel#VScroll(0, visualmode())
53 | nnoremap (WheelDown) :call wheel#VScroll(1, '')
54 | vnoremap (WheelDown) :call wheel#VScroll(1, visualmode())
55 |
56 | nnoremap (WheelLeft) :call wheel#HScroll(0, '')
57 | vnoremap (WheelLeft) :call wheel#HScroll(0, visualmode())
58 | nnoremap (WheelRight) :call wheel#HScroll(1, '')
59 | vnoremap (WheelRight) :call wheel#HScroll(1, visualmode())
60 |
61 | if !exists("g:wheel_no_mappings") || !g:wheel_no_mappings
62 | if exists('g:wheel#map#up') && g:wheel#map#up != ''
63 | exe 'nmap ' . g:wheel#map#up . ' (WheelUp)'
64 | exe 'vmap ' . g:wheel#map#up . ' (WheelUp)'
65 | endif
66 | if exists('g:wheel#map#down') && g:wheel#map#down != ''
67 | exe 'nmap ' . g:wheel#map#down . ' (WheelDown)'
68 | exe 'vmap ' . g:wheel#map#down . ' (WheelDown)'
69 | endif
70 |
71 | if exists('g:wheel#map#left') && g:wheel#map#left != ''
72 | exe 'nmap ' . g:wheel#map#left . ' (WheelLeft)'
73 | exe 'vmap ' . g:wheel#map#left . ' (WheelLeft)'
74 | endif
75 | if exists('g:wheel#map#right') && g:wheel#map#right != ''
76 | exe 'nmap ' . g:wheel#map#right . ' (WheelRight)'
77 | exe 'vmap ' . g:wheel#map#right . ' (WheelRight)'
78 | endif
79 |
80 | let s:regress = &wrap && !g:wheel#scroll_on_wrap
81 | if !s:regress && g:wheel#map#mouse ==# 1
82 | " natural
83 | map (WheelDown)
84 | map (WheelUp)
85 | elseif !s:regress && g:wheel#map#mouse ==# -1
86 | " reverse
87 | map (WheelUp)
88 | map (WheelDown)
89 | endif
90 | unlet s:regress
91 | endif
92 |
93 | let &cpo = s:save_cpo
94 | unlet s:save_cpo
95 |
96 | let g:wheel#loaded = 1
97 |
98 | " vim:ts=2:sw=2:sts=2
99 |
--------------------------------------------------------------------------------
/screenshots/demo-text.txt:
--------------------------------------------------------------------------------
1 | _ ___ _ ____ __
2 | | | / (_)_ _ ___| | /| / / / ___ ___ / /
3 | | |/ / / ' \/___/ |/ |/ / _ \/ -_) -_) /
4 | |___/_/_/_/_/ |__/|__/_//_/\__/\__/_/
5 |
6 |
7 | The down and up cursor movement of ‘j’ and ‘k’
8 | will be familiar to nearly all Vim users.
9 |
10 |
11 | Similarly, many Vim users will be familiar with
12 | the use of Ctrl-E and Ctrl-Y to scroll. Note how
13 | the cursor remains stationary on the document.
14 |
15 |
16 | Wheel combines the two to produce a new scrolling
17 | cursor movement with Ctrl-J and Ctrl-K. Note how
18 | they counter one another to maintain the cursor
19 | screen position.
20 |
21 |
22 | Be sure to check out the README and enjoy the
23 | plugin!
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/screenshots/demo.txt:
--------------------------------------------------------------------------------
1 |
2 | Captured with Quicktime.
3 |
4 | Processed with:
5 |
6 | $ ffmpeg -i ~/Desktop/nu2.mov -s 700x191 -pix_fmt rgb24 -r 10 -f gif - | \
7 | gifsicle --optimize=3 --delay=10 > ~/demo2.gif
8 |
9 |
--------------------------------------------------------------------------------
/screenshots/demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/preservim/vim-wheel/3aed582e945630e932d2c33e07816ab1ce4178df/screenshots/demo2.gif
--------------------------------------------------------------------------------