Skip to content

Commit

Permalink
Rename app
Browse files Browse the repository at this point in the history
  • Loading branch information
drzel committed Jan 27, 2018
1 parent 566fa39 commit 028d819
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# vim-scroll-off-fraction
# vim-scrolloff-fraction

Scroll off as a fraction of window height.
`scrolloff` as a fraction of window height.


## Why?

I don't like my cursor line getting too close to the top or the bottom of the
screen. But I also don't like it being a fixed number of lines, given varying
window heights, especially when splitting horizontally. This plugin allows you
to set scrolloff to a fraction of the total window height.
screen. But I also don't like it being an absolutely fixed number of lines,
given varying window heights, especially when splitting horizontally. This
plugin allows you to set `scrolloff` to a fraction of the total window height.


## Installation
Expand All @@ -18,20 +18,19 @@ Install with a plugin manager.

## Usage

By default the scrolloff will be set to the top and bottom 25% of the screen.
You can change it with:
By default `scrolloff` will be set to 25% of the active window height. You can
change it with:

```vim
" Default value
let g:scroll_off_fraction = 0.25
let g:scrolloff_fraction = 0.25
```

You can set an absolute scrolloff value for certain filetypes:
By default quickfix windows use an absolute `scrolloff` value of 0. You can set
an absolute scrolloff value for certain `filetypes`:

```vim
" Default values
let g:scroll_off_absolute_filetypes = ['qf']
let g:scroll_off_absolute_value = 0
let g:scrolloff_absolute_filetypes = ['qf']
let g:scrolloff_absolute_value = 0
end
```

Expand Down
28 changes: 14 additions & 14 deletions plugin/vim-scroll-off-fraction.vim
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
scriptencoding utf-8

" vim-scroll-off-fraction
" vim-scrolloff-fraction
" Author: Sheldon Johnson
" Version: 0.1
" Version: 0.2

if exists('g:loaded_scroll_off_fraction') || &compatible
if exists('g:loaded_scrolloff_fraction') || &compatible
finish
endif

let g:loaded_scroll_off_fraction = 1
let g:loaded_scrolloff_fraction = 1

if !exists('g:scroll_off_fraction')
let g:scroll_off_fraction = 0.25
if !exists('g:scrolloff_fraction')
let g:scrolloff_fraction = 0.25
end

if !exists('g:scroll_off_absolute_filetypes')
let g:scroll_off_absolute_filetypes = ['qf']
if !exists('g:scrolloff_absolute_filetypes')
let g:scrolloff_absolute_filetypes = ['qf']
end

if !exists('g:scroll_off_absolute_value')
let g:scroll_off_absolute_value = 0
if !exists('g:scrolloff_absolute_value')
let g:scrolloff_absolute_value = 0
end

function! ScrollOffFraction(fraction)
if index(g:scroll_off_absolute_filetypes, &filetype) == -1
if index(g:scrolloff_absolute_filetypes, &filetype) == -1
let l:visible_lines_in_active_window = winheight(win_getid())
let &scrolloff = float2nr(l:visible_lines_in_active_window * a:fraction)
else
let &scrolloff = g:scroll_off_absolute_value
let &scrolloff = g:scrolloff_absolute_value
endif
endfunction

augroup ScrollOffFraction
augroup ScrolloffFraction
autocmd!
autocmd BufEnter,WinEnter,WinNew,VimResized *,*.*
\ call ScrollOffFraction(g:scroll_off_fraction)
\ call ScrollOffFraction(g:scrolloff_fraction)
augroup END

0 comments on commit 028d819

Please sign in to comment.