Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 1 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
add comment

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
add comment

Your Answer

 
discard

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.