Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to only show on mouse scroll? #3

Closed
pinpox opened this issue Sep 18, 2020 · 9 comments
Closed

Option to only show on mouse scroll? #3

pinpox opened this issue Sep 18, 2020 · 9 comments

Comments

@pinpox
Copy link

pinpox commented Sep 18, 2020

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.

@Xuyuanp
Copy link
Owner

Xuyuanp commented Sep 19, 2020

Yes.

autocmd CursorHold * silent! lua require('scrollbar').clear()

@mawkler
Copy link

mawkler commented Sep 20, 2020

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

@Xuyuanp
Copy link
Owner

Xuyuanp commented Sep 21, 2020

set g:airline#extensions#clock#updatetime to a value larger than updatetime

@mawkler
Copy link

mawkler commented Sep 21, 2020

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.

@Xuyuanp
Copy link
Owner

Xuyuanp commented Sep 21, 2020

 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.

@Xuyuanp
Copy link
Owner

Xuyuanp commented Sep 21, 2020

eg.

autocmd CursorMoved * call MyScrollbarShow()

The trigger on CursorHold should be removed.

@mawkler
Copy link

mawkler commented Sep 22, 2020

@Xuyuanp Thanks, I'll give it a try!

@Xuyuanp Xuyuanp closed this as completed Sep 23, 2020
@jeromedalbert
Copy link

jeromedalbert commented Oct 3, 2020

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.

@jeromedalbert
Copy link

jeromedalbert commented Oct 3, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants