|
1 |
| -Vim ScrollMode |
2 |
| -=============== |
| 1 | +Scroll Mode for Vim |
| 2 | +=================== |
3 | 3 |
|
4 |
| -```vim |
5 |
| -let g:scroll_mode_mappings = { |
6 |
| - \ ":Bdelete<CR>": ["-"] |
7 |
| - \ } |
| 4 | +“Scroll mode” is a new mode for Vim that allows to scroll a text buffer with |
| 5 | +classical `h`/`j`/`k`/`l` bindings and some others, that are all designed for |
| 6 | +one-hand usage. Forget about `<C-f>`, `<C-d>`, and `G`. You don't need to keep |
| 7 | +holding modifier keys anymore — everything can be done with single-key |
| 8 | +mappings! |
8 | 9 |
|
9 |
| -nmap ξ{main}; <Plug>ScrollMode |
10 |
| -``` |
| 10 | +New key mappings available in the scroll mode: |
| 11 | + |
| 12 | +* `j` / `k` — scroll 5 lines down / up |
| 13 | +* `l` / `h` — scroll page down / up |
| 14 | +* `b` — scroll to the ending of the buffer (bottom) |
| 15 | +* `<Space>` — scroll to the beginning of the buffer |
| 16 | +* `;` — quit the scroll mode |
| 17 | +* `-` — quit the scroll mode and delete the buffer |
| 18 | + |
| 19 | +With these mappings, you can quickly look around, walk through several screens |
| 20 | +of text, and when you are in the right place return back to normal mode for |
| 21 | +more accurate text manipulations. |
11 | 22 |
|
12 |
| -TODO |
| 23 | +A comparison of pressed keys in normal mode and in the scroll mode: |
13 | 24 |
|
14 |
| -`g:scrollmode_actions` |
15 |
| -`g:scrollmode_mappings` |
16 |
| -`g:scrollmode_distance` |
| 25 | +| Normal Mode | Scroll Mode | |
| 26 | +| ------------------------------- | ------------------------ | |
| 27 | +| `shift` `g` | `b` | |
| 28 | +| `ctrl` `b` | `h` | |
| 29 | +| `ctrl` `b` | `h` | |
| 30 | +| `k` `k` `k` `k` `k` `k` `k` `k` | `j` `j` | |
| 31 | +| 13 keys (including 3 modifiers) | 5 keys, all for one hand | |
17 | 32 |
|
18 |
| -`g:scrollmode_cmdline_indicator` |
19 |
| -`g:scrollmode_airline_indicator` |
20 |
| -`g:scrollmode_statusline_highlight` |
| 33 | +Since scroll mode is in fact just a wrapper around normal mode, all keys, that |
| 34 | +are not affected continue to be available in the scroll mode: searching (`/`, |
| 35 | +`?`, `n`, `N`), window managing (`<C-w>`), etc. |
21 | 36 |
|
22 |
| -`g:scrollmode_statusline_group` |
23 |
| -`g:scrollmode_statusline_group_edge` |
| 37 | +Installation |
| 38 | +------------ |
24 | 39 |
|
25 |
| -### `g:ScrollmodeOnQuite` |
26 |
| -Funcref that is called on quit from the scroll mode. |
| 40 | +| Plugin Manager | Command | |
| 41 | +| --- | --- | |
| 42 | +| [vim-plug](https://github.com/junegunn/vim-plug) | `Plug 'GeneZharov/vim-scrollmode'` | |
| 43 | +| [Vundle](https://github.com/VundleVim/Vundle.vim) | `Plugin 'GeneZharov/vim-scrollmode'` | |
| 44 | +| [pathogen.vim](https://github.com/tpope/vim-pathogen/) | `git clone 'git@github.com:GeneZharov/vim-scrollmode.git ~/.vim/bundle/vim-scrollmode'` | |
| 45 | +| native pack | `git clone 'git@github.com:GeneZharov/vim-scrollmode.git' ~/.vim/pack/dist/start/vim-scrollmode` | |
| 46 | + |
| 47 | +Set a preferred shortcut to enter the scroll mode: |
27 | 48 |
|
28 | 49 | ```vim
|
29 |
| -function! s:fn() abort |
30 |
| - echo "scroll mode is over..." |
31 |
| -endfunction |
| 50 | +nmap <Leader>; <Plug>ScrollMode |
| 51 | +``` |
| 52 | + |
| 53 | +I prefer to use `<Space>` as a `<Leader>` key. You can achieve the same with: |
32 | 54 |
|
33 |
| -let g:ScrollmodeOnQuit = function("s:fn") |
| 55 | +```vim |
| 56 | +map <SPACE> <Nop> |
| 57 | +let mapleader = "\<Space>" |
34 | 58 | ```
|
| 59 | + |
| 60 | +Configuration |
| 61 | +------------- |
| 62 | + |
| 63 | +### Scrolling Settings |
| 64 | + |
| 65 | +* **`g:scrollmode_actions`** |
| 66 | + |
| 67 | + This option allows to configure default scroll mode key mappings. These |
| 68 | + key mappings are internally set with the following dictionary. |
| 69 | + |
| 70 | + ```vim |
| 71 | + \ { |
| 72 | + \ "up": ["k", "<Up>"], |
| 73 | + \ "down": ["j", "<Down>"], |
| 74 | + \ "pagedown": ["l"], |
| 75 | + \ "pageup": ["h"], |
| 76 | + \ "bottom": ["b"], |
| 77 | + \ "top": ["<Space>"], |
| 78 | + \ "exit": [";"], |
| 79 | + \ "bdelete": ["-"] |
| 80 | + \ } |
| 81 | + ``` |
| 82 | +
|
| 83 | + You can specify any subset of this dictionary as a value for this option in |
| 84 | + order to override default mappings. |
| 85 | +
|
| 86 | + For example, to add `<Esc>` key to the keys that exit the scroll mode: |
| 87 | +
|
| 88 | + ```vim |
| 89 | + let g:scrollmode_actions = { |
| 90 | + \ "exit": [";", "<Esc>"], |
| 91 | + \ } |
| 92 | + ``` |
| 93 | +
|
| 94 | + _I didn't make `<Esc>` to quit the scroll mode as default behavior, because |
| 95 | + in the terminal Vim (but not Neovim) it can break some complex keys like |
| 96 | + `<Up>` and `<Down>` while the scroll mode is active. If you are not going |
| 97 | + to use these keys in the scroll mode or if you use a different Vim version |
| 98 | + (GVim, Neovim), then you are welcome to use the config from the example |
| 99 | + above._ |
| 100 | +
|
| 101 | +* **`g:scrollmode_mappings`** |
| 102 | +
|
| 103 | + With this option, you can specify new mappings available in the scroll |
| 104 | + mode. This option has precedence over `g:scrollmode_actions`, so you can |
| 105 | + rebind a default action with any custom command. |
| 106 | +
|
| 107 | + For example, let's add a custom command for buffer deletion: |
| 108 | +
|
| 109 | + ```vim |
| 110 | + let g:scroll_mode_mappings = { |
| 111 | + \ ":Bdelete<CR>": ["-", "c"] |
| 112 | + \ } |
| 113 | + ``` |
| 114 | +
|
| 115 | + When the scroll mode is activated, this code will internally result to: |
| 116 | +
|
| 117 | + ```vim |
| 118 | + nnoremap <silent> <buffer> - :Bdelete<CR> |
| 119 | + nnoremap <silent> <buffer> c :Bdelete<CR> |
| 120 | + ``` |
| 121 | +
|
| 122 | +* **`g:scrollmode_distance`** |
| 123 | +
|
| 124 | + Number of lines to scroll at once by `j` / `k` (`"up"` and `"down"` |
| 125 | + actions). |
| 126 | +
|
| 127 | + *Default:* `5` |
| 128 | +
|
| 129 | +### Scrolling Indicators |
| 130 | +
|
| 131 | +* **`g:scrollmode_cmdline_indicator`** |
| 132 | +
|
| 133 | + Enables or disables the scroll mode indicator in the command line. The |
| 134 | + indicator looks similar to other indicators for built-in modes and looks |
| 135 | + like this: |
| 136 | +
|
| 137 | + ``` |
| 138 | + -- SCROLL -- |
| 139 | + ``` |
| 140 | +
|
| 141 | + *Default:* `v:true` |
| 142 | +
|
| 143 | +* **`g:scrollmode_statusline_highlight`** |
| 144 | +
|
| 145 | + Enables or disables StatusLine highlighting, when the scroll mode is |
| 146 | + activated. Has no effect with plugins that replace the status line |
| 147 | + ([Airline](https://github.com/vim-airline/vim-airline), |
| 148 | + [Powerline](https://github.com/powerline/powerline), |
| 149 | + [Lightline](https://github.com/itchyny/lightline.vim)). |
| 150 | +
|
| 151 | + _I am not fully satisfied with how this feature works, so it is disabled by |
| 152 | + default. But if you need scroll mode to be more noticeable and colorful, |
| 153 | + then you can enable this option. See the options below for color |
| 154 | + customization._ |
| 155 | +
|
| 156 | + *Default:* `v:false` |
| 157 | +
|
| 158 | +### Highlight Groups |
| 159 | +
|
| 160 | +Options for status line color customization. Only have effect if |
| 161 | +`g:scrollmode_statusline_highlight` is enabled. |
| 162 | +
|
| 163 | +* **`g:scrollmode_statusline_group`** |
| 164 | +
|
| 165 | + Highlight group that is used for `StatusLine` when the scroll mode |
| 166 | + is active. |
| 167 | +
|
| 168 | + *Default:* `"DiffAdd"` |
| 169 | +
|
| 170 | +* **`g:scrollmode_statusline_group_edge`** |
| 171 | +
|
| 172 | + Highlight group that is used for `StatusLine` when the scroll mode is |
| 173 | + active and the top/bottom edge of the buffer is reached. The color helps to |
| 174 | + notice that you can't scroll in that direction anymore. Specify `v:null` if |
| 175 | + you don't need this behavior. |
| 176 | +
|
| 177 | + *Default:* `"DiffChange"` |
| 178 | +
|
| 179 | +### Hooks |
| 180 | +
|
| 181 | +* **`g:ScrollmodeOnQuit`** |
| 182 | +
|
| 183 | + Funcref that is called after you exit the scroll mode. |
| 184 | +
|
| 185 | + ```vim |
| 186 | + function! s:fn() abort |
| 187 | + " ... your code |
| 188 | + endfunction |
| 189 | +
|
| 190 | + let g:ScrollmodeOnQuit = function("s:fn") |
| 191 | + ``` |
| 192 | +
|
| 193 | +License |
| 194 | +------- |
| 195 | +
|
| 196 | +MIT license |
0 commit comments