views:

143

answers:

2

You can keep the cursor line in the middle of the screen and then have the text scroll underneath it by setting the scrolloff to a very large number. Ex:

:let &scrolloff = 999

To read more about how this works:

:help scrolloff

I love this feature and use it all the time but I would like the ability to keep the cursor at other locations other than the middle of the screen. For instance I would like the ability to keep the cursor at the top of the window and have the file scroll underneath it. I am pretty sure there is nothing natively available in vim to do this so I was wondering if anyone had come up with a light wieght vim script snippet to do this (or can someone come up with such a script)?


Here is my little .vimrc helper code to swich the position of the cursor quickly:

" SCROLLFIX SHORTCUTS
function! ToggleMyScrollFix()
  if ( g:scrollfix == 5 )
    let g:scrollfix = 50
  elseif ( g:scrollfix == 50 )
    let g:scrollfix = 95
  elseif ( g:scrollfix == 95 )
    let g:scrollfix = 5
  else
    let g:scrollfix = 50
  endif
endfunction
nnoremap  <silent> zz :call ToggleMyScrollFix()<CR>lh
+4  A: 

Check out the scrollfix plugin. I used it a couple years ago, so I don't know if it'll still work with the latest snapshots of Vim -- but at worst, it should give you a pretty good start at modifying it to work for you.

thedz
Perfect! Yep that is exactly what I needed and it works well... Thanks a ton..
stephenmm
A: 

You could do this:

nmap <C-Down> <C-E><Down>
nmap <C-Up> <C-Y><Up>
Brian Carper