In Vim, I don't like how when you reach end of file it puts the last line at the bottom of the screen.

Is there anyway to make the last line be something like 10 lines above the bottom of the screen and just make blank lines under it?

  • 2
    When your cursor reach the last line of the file, if you hit zz it will redraw the screen and position the current line at the center of the window which should display a few ~ lines after EOF. – user9433424 May 9 '16 at 16:49
  • yes, but if you move the cursor again positioning it at the bottom again. – Miguel Vera May 9 '16 at 18:00
  • 3
    It sounds like you have the scrolloff option set. Try :set scrolloff=0 and that behavior should change. – Tumbler41 May 9 '16 at 18:02
  • 1
    You can read your answer here: stackoverflow.com/questions/7406814/… There are more answers to this, basically it is not possible, only with workarounds. – mike May 9 '16 at 19:29
  • Indeed the behavior has been corrected! thank you – Miguel Vera May 10 '16 at 16:21

You can use ctrlE to scroll down your file, when you are at the end of the file it will add "virtual" line so the last line of the file is not at the bottom of the windows.

Additionally you can use the option scrolloff to always let some lines after your cursor, add this to your .vimrc:

set scrolloff=10

For more details see :h 'scrolloff' and :h CTRL-E.

| improve this answer | |
  • 2
    Unfortunately, setting scrolloff to 10 will still not show lines AFTER EOF like OP wanted. – Tumbler41 May 9 '16 at 19:17
  • Indeed, that's why I suggested using CTRL-E and ̀scrolloff was just "additional". Now it is a partial solution, OP is free not to accept it since it doesn't completely answer the question. – statox May 9 '16 at 20:03
  • 2
    Although it is just a partial solution i think CTRL-E is what i was looking for. I'd love if there was a way to display the lines after EOF automatically though. – Miguel Vera May 10 '16 at 17:29
  • @Miguel I'm glad it fits your needs. I think it could be possible to create a mapping which would call <C-e> when you scroll down but I'm really not sure it would work correctly... I'll try and see what is possible to do but I'm not sure I'll be able to create something convenient. – statox May 10 '16 at 17:36

The easiest solution, in my opinion, was adding zz to j and k. It has the major side effect of centering your cursor. I don't mind and much prefer it to craning my neck. I tried scrolloff and CTRL-E is just uncomfortable.

Type the following in : or .vimrc

nnoremap j jzz

nnoremap k kzz

Sourced: http://vim.wikia.com/wiki/Keep_your_cursor_centered_vertically_on_the_screen

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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