Skip to content

Commit

Permalink
Add <Plug> mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Jan 5, 2021
1 parent 057ec56 commit 64de102
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
33 changes: 22 additions & 11 deletions doc/scrollview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ Use |packages| or one of the various package managers.

* |nvim-scrollview| works automatically, displaying (non-interactive)
scrollbars.

*scrollview-commands*
* The *:ScrollViewDisable* command disables scrollbars.
* The *:ScrollViewEnable* command enables scrollbars. This is only necessary
if scrollbars have previously been disabled.
* The *:ScrollViewRefresh* command refreshes the scrollbars. This is relevant
when the scrollbars are out-of-sync, which can occur e.g., as a result of
some window arrangement actions (see |scrollview-issues|).

*scrollview-mappings*
The following |<Plug>| mappings are defined for convenience.

Left-hand-side Right-hand-side
-------------- ---------------
`<Plug>(ScrollViewDisable)` `<cmd>ScrollViewDisable<cr>`
`<Plug>(ScrollViewEnable)` `<cmd>ScrollViewEnable<cr>`
`<Plug>(ScrollViewRefresh)` `<cmd>ScrollViewRefresh<cr>`

============================================================================
4. Configuration *scrollview-configuration*

Expand Down Expand Up @@ -138,29 +149,27 @@ Synchronization Issues ~
is triggered by the window arrangement actions. |:ScrollViewRefresh|, or
scrolling can be used to refresh the scrollbars.
- Workaround: Remap the problematic key sequences accordingly. >
nnoremap <silent> <c-w>H <c-w>H:silent! ScrollViewRefresh<cr>
nnoremap <silent> <c-w>J <c-w>J:silent! ScrollViewRefresh<cr>
nnoremap <silent> <c-w>K <c-w>K:silent! ScrollViewRefresh<cr>
nnoremap <silent> <c-w>L <c-w>L:silent! ScrollViewRefresh<cr>
nmap <silent> <c-w>H <c-w>H<plug>(ScrollViewRefresh)
nmap <silent> <c-w>J <c-w>J<plug>(ScrollViewRefresh)
nmap <silent> <c-w>K <c-w>K<plug>(ScrollViewRefresh)
nmap <silent> <c-w>L <c-w>L<plug>(ScrollViewRefresh)
< This won't resolve the issue in all cases (e.g., when using |:wincmd|).

* Scrollbars become out-of-sync when the mouse wheel is used to scroll a
non-current window. This is because the |WinScrolled| event only corresponds
to the current window. The scrollbars can be refreshed with
|:ScrollViewRefresh|, scrolling, or by changing the current window.
- Workaround: Remap the problematic key sequences accordingly. >
nnoremap <silent> <scrollwheelup>
\ <scrollwheelup>:silent! ScrollViewRefresh<cr>
nnoremap <silent> <scrollwheeldown>
\ <scrollwheeldown>:silent! ScrollViewRefresh<cr>
nmap <silent> <scrollwheelup> <scrollwheelup><plug>(ScrollViewRefresh)
nmap <silent> <scrollwheeldown> <scrollwheeldown><plug>(ScrollViewRefresh)
* Scrollbars become out-of-sync after fold commands when using a
|scrollview-mode| that accounts for folds. Because there are no |autocmd-events|
for folding, the plugin is unable to refresh the scrollbars.
- Workaround: Remap the problematic fold command key sequences accordingly,
depending on the fold commands you use. >
nnoremap <silent> zo zo:silent! ScrollViewRefresh<cr>
nnoremap <silent> zc zc:silent! ScrollViewRefresh<cr>
nmap <silent> zo zo<plug>(ScrollViewRefresh)
nmap <silent> zc zc<plug>(ScrollViewRefresh)
Error Message Issues ~
*scrollview-error-message-issues*
Expand All @@ -181,7 +190,9 @@ Error Message Issues ~
\ <c-w>c
\ :silent! ScrollViewEnable<cr>
< This won't resolve the issue in all cases (e.g., when using |:close| or
|:wincmd|).
|:wincmd|). |<Plug>| mappings cannot be used, as they require recursive maps,
and <c-w>c would infinitely recurse, as its usage on the right-hand-side
is not at the beginning (see |recursive_mapping| for details).

* Deleting a buffer with |:bdelete|, when it's the only visible buffer and there
are multiple buffers on the buffer list, results in the following error (with
Expand Down
2 changes: 2 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
flexible scrollview.txt /*flexible*
nvim-scrollview scrollview.txt /*nvim-scrollview*
scrollview-color-customization scrollview.txt /*scrollview-color-customization*
scrollview-commands scrollview.txt /*scrollview-commands*
scrollview-configuration scrollview.txt /*scrollview-configuration*
scrollview-error-message-issues scrollview.txt /*scrollview-error-message-issues*
scrollview-installation scrollview.txt /*scrollview-installation*
scrollview-issues scrollview.txt /*scrollview-issues*
scrollview-mappings scrollview.txt /*scrollview-mappings*
scrollview-modes scrollview.txt /*scrollview-modes*
scrollview-requirements scrollview.txt /*scrollview-requirements*
scrollview-synchronization-issues scrollview.txt /*scrollview-synchronization-issues*
Expand Down
14 changes: 14 additions & 0 deletions plugin/scrollview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ if !exists(':ScrollViewDisable')
command -bar ScrollViewDisable :call s:ScrollViewDisable()
endif

" *************************************************
" * Mappings
" *************************************************

" <plug> mappings are defined for convenience of creating user-defined
" mappings that call nvim-scrollview functionality. However, since the usage
" of <plug> mappings requires recursive map commands, this prevents mappings
" that both call <plug> functions and have the left-hand-side key sequences
" repeated not at the beginning of the right-hand-side (see :help
" recursive_mapping for details).
noremap <plug>(ScrollViewDisable) <cmd>ScrollViewDisable<cr>
noremap <plug>(ScrollViewEnable) <cmd>ScrollViewEnable<cr>
noremap <plug>(ScrollViewRefresh) <cmd>ScrollViewRefresh<cr>
" *************************************************
" * Core
" *************************************************
Expand Down

0 comments on commit 64de102

Please sign in to comment.