Scroll bar for vim(curses-based one, not gvim)?

If you are considering the "write your own plugin" route, Vim's 'sign' feature might be a good place to start. This feature is how e.g., syntax checking plugins highlight errors.

vim sign example

A simple approach to place the sign would then be:

  1. Determine where you are in the file as a percentage p
  2. Determine how many lines are visible in the vim windows L
  3. Place a sign at the line number closest to int(p*L)
  4. Recalculate on movement around the file

It is possible to use the statusline as a scrollbar. I used to have the following in my .vimrc, which emulates a scrollbar (also it is only horizontally, but it works surprisingly well). This was originally discussed on the vim_use Mailinglist some years ago.

func! STL()
  let stl = '%f [%{(&fenc==""?&enc:&fenc).((exists("+bomb") && &bomb)?",B":"")}%M%R%H%W] %y [%l/%L,%v] [%p%%]'
  let barWidth = &columns - 65 " <-- wild guess
  let barWidth = barWidth < 3 ? 3 : barWidth

  if line('$') > 1
    let progress = (line('.')-1) * (barWidth-1) / (line('$')-1)
  else
    let progress = barWidth/2
  endif

  " line + vcol + %
  let pad = strlen(line('$'))-strlen(line('.')) + 3 - strlen(virtcol('.')) + 3 - strlen(line('.')*100/line('$'))
  let bar = repeat(' ',pad).' [%1*%'.barWidth.'.'.barWidth.'('
        \.repeat('-',progress )
        \.'%2*0%1*'
        \.repeat('-',barWidth - progress - 1).'%0*%)%<]'

  return stl.bar
endfun

hi def link User1 DiffAdd
hi def link User2 DiffDelete
set stl=%!STL()

Make sure you have the laststatus option set to 2.