3

How can I disable that vim lets me scroll past the end of a file?

2

4 Answers 4

4

Vim doesn't actually let you scroll past the end of the file (as in, move the cursor past the last existing line), but it shows you a few lines behind the last one, because it has to show something.

It cannot be disabled, sorry. Not unless you wish to download Vim's sources (it is open source, after all) and fiddle with it. It natively inserts ~'s on rows that don't exist, because, well, it has to show something. All editors do that.

As someone suggested, there are workarounds around this ... but that is all they are - workarounds. And none of them work really pretty. I wouldn't recommend any of them.

3

Once you reach the end of the file, you can use zz or zt to move the current line to the middle or top of the window respectively. You can do this whenever, regardless of the location in the file. The scrolloff setting will make the cursor stay for example 5 lines from either the top or bottom of the window if you have it set to 5 (set scrolloff=5). However, this does not work when you get to the top or bottom of the file.

0

Without a fairly ugly hack that would probably look visually disturbing and slow Vim down, you can't do what you want. Basically you would have to set up something like an autocmd for the CursorMoved/CursorMovedI events that tried to detect whether the bottom of the file was displayed, and if so, execute some normal mode commands to force the scroll position.

It is worth noting (and as the people at link that johnny provided in his comment say), Vim is not the only application that behaves like this, and you can't really scroll past the end of a file in Vim—the last line must always be visible.

0

If you don't mind that it moves the cursor, this works:

noremap <ScrollWheelUp> H5k
noremap <ScrollWheelDown> L5j

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .