sponsor Vim development Vim logo Vim Book Ad

Smooth Center : Smoothly centres display when you press Esc like zz, zt and zb

 script karma  Rating 0/4, Downloaded by 582    Comments, bugs, improvements  Vim wiki

created by
Paul Contreras
script type
Normal VIM lets you center the file based on the current cursor position when you press zz, zt and zb.  This is nice but wouldn't it be nicer if this centering took place smoothly, like panning across a scene of a movie.  This script gives you this: Esc, SHIFT-Esc and SHIFT-F1 in Normal mode work like for zz, zt and zb respectively.  You can cancel by re-pressing Esc.   Script correctly accounts for 'scrolloff' setting.  Note: the default updatetime should be lowered to see this or else it will not appear to do anything.  The default is 4000 but I use 650.  There are some glitches in the Center (Normal mode / ESC) like the scrolling keeps going back in on itself when there are folds present, and the scrolling tries to continue if you are at the bottom of the buffer.  These do not affect S-Esc / S-F1, (zb and zt equivs. respectively) and works ok if there are no folds or you are not at the bottom of the script.  Working on these!! :)
install details
Paste it in your _vimrc file. Replace obviously if it is already there.  It is obviously marked.    If you see no scrolling happen, do set ut=1000, because sometimes having a low ut makes the timer not work. Speaking of which, you should have this Timer somewhere in your vimrc, because this makes automatic scrolling possible.  http://www.vim.org/scripts/script.php?script_id=3244

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
SmoothCenter.vim 1.7 2010-09-17 7.0 Paul Contreras Made improvements to scroll till cursor is on top and cursor is at bottom cases.  These work very reliably when in folded mode.  The center case is not quite stable but kind of works, there are still some glitches in folded mode and when the buffer is scrolled near the bottom.
SmoothCenter.vim 1.6 2010-08-23 7.0 Paul Contreras Had a slight glitch that happened but not always when you did Shift-ESC, the scrolling would just continue. Not sure why but fixed it and checked it so that this does not happen.  Had a bug that caused the continuing of scrolling when line wrapping was on. This gave incorrect readings for the window height so that scrolling would continue.  Fixed this by putting in a check that warns you if wrap is on, and doesn't scroll.
SmoothCenter.vim 1.5 2010-08-16 6.0 Paul Contreras Sorted out some funky messy logic where 'zb' equivalent in normal vim in Smooth Center did not work, if the cursor was parked on the last line. (S-ESC).  Nothing happened.  Obviously fixed it now so that it does.
SmoothCenter.vim 1.4 2010-08-07 6.0 Paul Contreras Fixed a subtle bug that meant that if scrolloff>0 the display would keep on centering but not immediately. If you were at the top of bottom having done S-ESC or S-F1 with scrolloff>0 then the display would stop scrolling then, but then later on when you moved off that line the display would keep on trying to scroll. This was to do with where I had attempted to account for the 'scrolloff' value in the centering bit of my code.  Made the command line clear so that you don't see a silly 'call StartSmoothCentering()' at the bottom of the screen each time.
SmoothCenter.vim 1.3 2010-08-07 6.0 Paul Contreras Fixed the glitch where if you had a scrolloff>0 set it would carry on scrolling if you were at the top and bottom and you did a S-ESC or S-F1.  Now correctly identifies the scrolloff setting and accounts for this value, not just the cursors position within the current window.  Changed key mappings to be a more natural-feeling S-ESC gets you 'out of the code', in other words lets you see where you are by scrolling the file down, whereas S-F1 scrolls up and hence further deep into the file.
SmoothCenter.vim 1.2 2010-08-04 6.0 Paul Contreras Had a bug where the end cases were not being detected properly, the top of the file and the end of the file respectively. I got them confused, so it looked like the scrolling wouldn't start if the first line was showing when you press S-Esc.
SmoothCenter.vim 1.1 2010-08-01 6.0 Paul Contreras Cured the glitch that the centering is not centering when the end of the file is not as far as the bottom of the window.  Added a couple of new modes, these act just like zt and zb in normal mode. They are shift-ESC and shift-F1 respectively.  So now you've got all zz, zt & zb as smooth-equivalents: ESC, S-ESC and S-F1 respectively.
SmoothCenter.vim 1.0 2010-07-14 6.0 Paul Contreras Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo