46

It is very inconvenient when the line I'm editing is at the bottom of the screen . Because you can't see any following lines and that prevent you from take any "eye refernce" to the content of the file following the current line .

so my question is there a vim command can refresh the display and put the current line under edit to on the top of the screen ? thanks in advance.

3 Answers 3

79

See this reference.

z<return>
3
  • 5
    fyi the link is no longer valid.
    – Anne
    Feb 5, 2013 at 14:50
  • Updated reference to vimdoc, not sure if it's official, but has the correct info.
    – mtk
    Jan 21, 2014 at 13:52
  • 12
    Gotta mention zt. Same dealie only it maintains cursor position. It's way less convenient to type, of course, but you can always swap the mappings. Oct 31, 2015 at 6:18
60

:h scroll-cursor

Jonathan's answer is valid, however I prefer zt (as "top") that keeps the cursor where it was. In the same idea, there is zb (as "bottom") and zz (not as "middle", but that puts the current line at the center of the window).

1
  • 18
    This answer is better than mine. I'm Jonathan Feinberg, and I approved this message. Feb 17, 2010 at 15:42
15

There is also an option to make vim always show context around the current line:

:set scrolloff=5

(or, :se so=5) will show +/−5 lines around your current line. From vim's help about 'scrolloff':

Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. If you set it to a very large value (999) the cursor line will always be in the middle of the window (except at the start or end of the file or when long lines wrap).

1
  • vim just keeps getting better! does vim ~/.vim/vimrc<cr>4Goset scrolloff=1<esc>ZZ Nov 8, 2015 at 21:14

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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