I often find scrolling a full page too disorienting, half a page too much, but a quarter page is just right. I currently do it just by holding down the arrow keys.
How do I scroll 25% of the page down and up easily?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Maybe ctrld and ctrlu could be what you are looking for. By default they move half of the screen.
Scroll window Downwards in the buffer. The number of lines comes from the 'scroll' option (default: half a screen).
If [count] given, first set 'scroll' option to [count].
Which means that the first time you want to scroll in a window you can do XXctrld where XX is the 25% of the number of lines in your window. As it sets
scroll to the XX value you can then use ctrld and ctrlu to move 25% of the screen.
Also, I think that
:h scrolling might be interesting for you.
And here is another solution with a function and some mappings to add to your
function! ScrollQuarter(move) let height=winheight(0) if a:move == 'up' let key="\<C-Y>" else let key="\<C-E>" endif execute 'normal! ' . height/4 . key endfunction nnoremap <silent> <up> :call ScrollQuarter('up')<CR> nnoremap <silent> <down> :call ScrollQuarter('down')<CR>
The function will get the height of the current window, and accordingly to its parameter will scroll the screen up or down of a quarter of the height.
The mappings will call the function, the first one to go up and the second one to go down.
Of course, you can change
<down> to some other keys if you want to keep the default behavior of your arrow keys.
You can use ctrle and ctrly to move the page by one line up and down.
Then if you want for +/- 25% to be moved you can use 20ctrle and that will move you 20 lines down.
Here is also a good explained question that is similiar to yours: https://stackoverflow.com/questions/3458689/how-to-move-screen-without-moving-cursor-in-vim
I variated statox approach so it scrolls more consistent over the linewraps. If you want a quarter step, change 0.618 back to 0.25 or whatever.
function! ScrollGolden(move) let height=winheight(0) if a:move == 'up' let prep='L' " let key="^Y" let key='gk' let post='zb' elseif a:move == 'down' let prep='H' " let key="^E" let key='gj' let post='zt' endif execute 'normal! ' . prep . float2nr(round(height*0.618)) . key . post endfunction nnoremap <silent> <BS> :call ScrollGolden('up')<CR> nnoremap <silent> <Space> :call ScrollGolden('down')<CR>
If your wanting a good general answer and not an exact 25% you could factor the normal line count on a page by divide by 25 and set some system mappings. For instance if you normally have about 100 line on a screen at a time then 25% of that is 25 lines so you could set a key mapping on something like your capital J and K for quickly moving up and down 25 lines
noremap J 25j noremap K 25k
If your wanting to just jump to the quarter mark of the entire file then in normal mode just type:
Here are simple one-line mappings that don't require a separate function. Putting these in your .vimrc will cause CTRL-j and CTRL-k to respectively move down or up 1/4 of the screen in insert, visual, and normal modes.
" insert mode inoremap <expr> <C-j> '<ESC>'.winheight(0)/4.'<C-D>a' inoremap <expr> <C-k> '<ESC>'.winheight(0)/4.'<C-U>a' " visual mode vnoremap <expr> <C-j> winheight(0)/4.'<C-D>' vnoremap <expr> <C-k> winheight(0)/4.'<C-U>' " normal mode nnoremap <expr> <C-j> winheight(0)/4.'<C-D>' nnoremap <expr> <C-k> winheight(0)/4.'<C-U>'
Adapted from this Reddit answer.
Bonus: Combine with the vim-smoothie plugin for animated smooth scrolling. If do this, replace
nmap to allow nested overrides of the keybindings.