Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim - Stop scrolling after first file ending

Tags:

vim

By default when you scroll down to the end of a displayed buffer in a vim window, you can scroll until the last file line is on first line of the vim display area. All other lines of the display area are marked with "~" characters. Is there a configuration to stop scrolling when the last file line is at the bottom of the vim window?

Edit: To be more precise this behavior only apply to mouse wheel scroll or PgDown key navigation that fill the screen with those non-existant line marks. I the cursor is moved line by line using the down arrow key, it stops correctly at the last file line.

like image 911
greydet Avatar asked Nov 05 '11 22:11

greydet


2 Answers

Simply zb to align the current line to the bottom of the window.

E.g. Gzb

Not surpisingly there is a family of related panning motions:

  • zj down
  • zk up
  • zt top
  • zb bottom
  • zz center (middle)
  • zz center (middle)

For completeness:

  • zl / zL vertical pan to the right
  • zh / zH vertical pan to the left

Also, have a look at scrolloff

I use

:set scrolloff=2

to always keep a minimum buffer of 2 lines before or after the current cursor line. This makes these panning motions almost magical. I spend all day browsing code bases using nothing but

  • paging C-d/C-u, hjkl, and frequent panning relocations with (mostly) zz
  • navigating }/{
  • ctags for all other navigation needs
like image 56
sehe Avatar answered Oct 26 '22 08:10

sehe


I don't think so. But even if there were, how would you want it to behave if there were less lines in your file than on your screen? You'd have to display those non-existent lines somehow.

You'd have to have some way to tell vim to display those lines if the top of the file is in view, but not allow them to display if the top isn't in view.

like image 42
John Weldon Avatar answered Oct 26 '22 07:10

John Weldon