RusAlex
RusAlex

Reputation: 8575

Can I scroll the file up or down in an inactive window in Vim?

Say, I split my Vim screen into two windows. And I need to scroll inactive window. Example to scroll up/down preview window without placing a cursor into preview window.

Upvotes: 7

Views: 1433

Answers (2)

SergioAraujo
SergioAraujo

Reputation: 11800

"this function maps Alt-down and Alt-Up to move other window
" put in your ~/.vimrc
fun! ScrollOtherWindow(dir)
    if a:dir == "down"
        let move = "\<C-E>"
    elseif a:dir == "up"
        let move = "\<C-Y>"
    endif
    exec "normal \<C-W>p" . move . "\<C-W>p"
endfun
nmap <silent> <M-Down> :call ScrollOtherWindow("down")<CR>
nmap <silent> <M-Up> :call ScrollOtherWindow("up")<CR>

Upvotes: 1

DrAl
DrAl

Reputation: 72616

You could add a couple of custom mappings:

:nmap ,d <C-W>W<C-D><C-W>W
:nmap ,u <C-W>W<C-U><C-W>W

and then use ,d and ,u to scroll down and up in the other window.

Upvotes: 5

Related Questions