Option to only show on mouse scroll?
Closed this issue · 9 comments
Small feature request:
Would it be possible to show it only when I'm scrolling with the mouse wheel?
When using vim as a file viewer I would love a scrollbar.
Yes.
autocmd CursorHold * silent! lua require('scrollbar').clear()
I had problems getting this working and was able to boil it down to the configuration below. It seems that vim-airline-clock (together with vim-airline) is the problem. For some reason the scrollbar never goes away on CursorHold
with the following configuration. If I remove vim-airline-clock
the scrollbar dissapears on CursorHold
as expected. What could be the reason for this?
call plug#begin('~/.vim/bundle')
Plug 'bling/vim-airline'
Plug 'enricobacis/vim-airline-clock'
Plug 'Xuyuanp/scrollbar.nvim'
call plug#end()
augroup scrollbar
autocmd!
autocmd BufEnter * silent! lua require('scrollbar').show()
autocmd BufLeave * silent! lua require('scrollbar').clear()
autocmd CursorMoved * silent! lua require('scrollbar').show()
autocmd VimResized * silent! lua require('scrollbar').show()
autocmd FocusGained * silent! lua require('scrollbar').show()
autocmd FocusLost * silent! lua require('scrollbar').clear()
autocmd CursorHold * silent! lua require('scrollbar').clear()
augroup end
set updatetime=500
set g:airline#extensions#clock#updatetime
to a value larger than updatetime
Thanks, that solved it!
How would I go about getting the scrollbar to stay longer than updatetime
? I use some other plugins that work better with a low updatetime
value, while I would like the scrollbar to stay visible for longer before being cleared. Would it be possible to tweak the line
autocmd CursorHold * silent! lua require('scrollbar').clear()
in some way to add some (non-blocking) delay before calling clear()
? I'm not yet familiar with the Lua API.
function! MyScrollbarShow() abort
let l:winnr = 0
let l:bufnr = bufnr()
if exists('b:scrollbar_timer_id') | call timer_stop(b:scrollbar_timer_id) | endif
call luaeval('require("scrollbar").show(_A[1], _A[2])', [l:winnr, l:bufnr])
let b:scrollbar_timer_id = timer_start(4000, {-> luaeval('require("scrollbar").clear(_A[1], _A[2])', [l:winnr, l:bufnr])}, {'repeat': 1})
endfunction
Use the function above instead of the default lua require('scrollbar').show
.
PS. This function has not been fully tested.
PS. Please perform an update firstly, I just pushed some bugfixes.
Maybe this should be a feature integrated.
eg.
autocmd CursorMoved * call MyScrollbarShow()
The trigger on CursorHold
should be removed.
The solutions above show the cursor whenever the cursor is moved, even if you move it just horizontally within the same line, or if you move it vertically with j
/ k
but you are not moving the vim screen.
@pinpox asked for an "option to only show on mouse scroll", which can be interpreted as "only show when the VIM screen is scrolled. I personally have this need since I am used to macOS' default behavior of only showing scrollbars when you scroll.
I think it's probably doable in Vimscript; it doesn't look like there is a scrolling event, but one could use CursorMoved
along with detecting if the first line number in the screen has changed since the last move. I'll try to do that shortly.
Here's my hack to show the scrollbar only when the screen itself scrolls:
augroup configure_scrollbar
autocmd!
autocmd CursorMoved * call ShowScrollbar()
autocmd CursorHold,BufLeave,FocusLost,VimResized,QuitPre * silent! lua require('scrollbar').clear()
augroup end
set updatetime=500
function! ShowScrollbar()
if !exists('b:previous_first_visible_linenum') | return | endif
let first_visible_linenum = line('w0')
if first_visible_linenum != b:previous_first_visible_linenum
silent! lua require('scrollbar').show()
end
let b:previous_first_visible_linenum = first_visible_linenum
endfunction
function! OnBufEnter()
if !exists('b:previous_first_visible_linenum')
let b:previous_first_visible_linenum = line('w0')
endif
endfunction
augroup general_autocommands
autocmd!
autocmd BufEnter * call OnBufEnter()
augroup end
PS: This does not show the scrollbar when scrolling with ctrl + e
and ctrl + y
unless you press them enough for the cursor to scroll, but it's good enough for me for now.
PSS:
Maybe this should be a feature integrated.
I agree, maybe an option like let g:scrollbar_show_on_scroll = true
.