Prince Billy Graham
Prince Billy Graham

Reputation: 3618

Vim - How to keep scrolling automatically up or down until I stop it (without any plugin)

I want to give a command to start scrolling window automatically up or down until I stop it using any key press or any other command. I want to do it without installing any plugin.

Upvotes: 0

Views: 677

Answers (3)

Marko Mahnič
Marko Mahnič

Reputation: 735

You can scroll with these commands from the command line:

:while 1 | let c=getchar(1) | if c != 0 | break | else | exec "norm! gj" | sleep 60 m | redraw | endif | endwhile

The scrolling will end when you press any key. You can adjust the speed by changing the sleep parameter.

You can create a command:

:command Scroll while 1 | let c=getchar(1) | if c != 0 | break | else | exec "norm! gj" | sleep 60 m | redraw | endif | endwhile

and then use

:Scroll

Upvotes: 2

svlasov
svlasov

Reputation: 10455

Adjust this script to your liking, for example increase s:timer_msec and set a more suitable mapping. Save it e.g. as vim/plugin/lyrics/lyrics.vim.

func! s:handler(timer)
  exec "norm! \<C-e>"
endfunc

func! AutoScrollToggle()
  if !exists("s:scroll_timer")
    let s:scroll_timer = timer_start(s:timer_msec, funcref('s:handler'), {'repeat': -1})
  else
    call timer_stop(s:scroll_timer)
    unlet s:scroll_timer
  endif
endfunc

let s:timer_msec = 200
map <C-s> :call AutoScrollToggle()<CR>

Then use ctrl+s to toggle the scrolling.

Upvotes: 1

user10480385
user10480385

Reputation:

You can use the following keyboard shortcuts to scroll up and down. To continuously scroll, just hold them down.

k - Scroll up one line
j - Scroll down one line
Ctrl+b - Scroll up one full screen
Ctrl+f - Scroll down one full screen
Ctrl+u - Scroll up half screen
Ctrl+d - Scroll down half screen

Upvotes: 0

Related Questions