Skip to content

Instantly share code, notes, and snippets.

@mheiber
Last active October 12, 2021 20:14
Show Gist options
  • Save mheiber/45678d13b4351b102711e9261dd3950f to your computer and use it in GitHub Desktop.
Save mheiber/45678d13b4351b102711e9261dd3950f to your computer and use it in GitHub Desktop.
" add visual indication of progress in a buffer to the status bar. To use:
" set statusline=%{ProgRock()}REST_OF_YOUR_STATUS_LINE HERE}
" for example:
" set statusline=%{ProgRock()}%{coc#status()}%{get(b:,'coc_current_function','')}
function! ProgRock()
let magic_width_number = 30
let width = winwidth(0)
let lcur = line('.')
let lend = line('$')
let full = max([width - magic_width_number, 3])
let cur_render = float2nr((lcur / (lend + 0.0)) * full)
let rem_render = (full - cur_render) - 1
return '|' . RepeatStr('_', cur_render) . RepeatStr(' ', rem_render) . '|'
endfunction
function RepeatStr(str, n)
let res = ''
for _ in range(max([a:n, 0]))
let res .= a:str
endfor
return res
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment