Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Resize your terminal so it only shows one line apart from any header. Then make sure to never open a zero-line file. – Eroen Jan 23 '12 at 19:39
up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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

noremap <ScrollWheelUp> H5k
noremap <ScrollWheelDown> L5j
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.