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

improve ^F and ^B by handling 'window' and 'wrap' options #13

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ replaces. That is, every command should still behave exactly as described in
which hopefully will be addressed in the future:

* `^D`, `^U`, `^F`, `^B` should beep when they can't move any further.
* `^F` and `^B` should respect the `window` option.
* Native commands may move in a smarter way over wrapped/folded lines.


Expand Down
28 changes: 26 additions & 2 deletions autoload/smoothie.vim
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ function s:count_to_scroll()
end
endfunction

""
" Helper function to figure out how many lines ^F and ^B should scroll, taking
" the 'window' and 'wrap' options into account like the native commands do
function s:get_window_height()
let l:lines_to_scroll = winheight(0) - 2

if winnr('$') == 1 && &window < &lines - 1 " from :h 'window'
let l:lines_to_scroll = max([&window - 2, 1])

elseif &wrap
let l:lines_wrapped = line('w$') - line('w0') - 1
setl nowrap
let l:lines_unwrapped = line('w$') - line('w0') - 1
setl wrap

let l:number_of_lines_on_screen_that_wrap = l:lines_unwrapped - l:lines_wrapped
let l:lines_to_scroll -= l:number_of_lines_on_screen_that_wrap
endif

return l:lines_to_scroll
endfunction

""
" Smooth equivalent to ^D.
function smoothie#downwards()
Expand All @@ -191,11 +213,13 @@ endfunction
""
" Smooth equivalent to ^F.
function smoothie#forwards()
call s:update_target(winheight(0) * v:count1)
let l:winheight = s:get_window_height()
call s:update_target(l:winheight * v:count1)
endfunction

""
" Smooth equivalent to ^B.
function smoothie#backwards()
call s:update_target(-winheight(0) * v:count1)
let l:winheight = s:get_window_height()
call s:update_target(-l:winheight * v:count1)
endfunction