How to move screen without moving cursor in Vim

cursor-positionscrollvim

I recently discovered Ctrl+E and Ctrl+Y shortcuts for Vim that respectively move the screen up and down with a one line step, without moving the cursor.

Do you know any command that leaves the cursor where it is but moves the screen so that the line which has the cursor becomes the first line? (having a command for the last line would be a nice bonus).

I can achieve this by manually pressing Ctrl+E (or Ctrl+Y) the proper number of times, but having a command that somehow does this directly would be nice.

Any ideas?

Best Answer

  • zz - move current line to the middle of the screen
    (Careful with zz, if you happen to have Caps Lock on accidentally, you will save and exit vim!)
  • zt - move current line to the top of the screen
  • zb - move current line to the bottom of the screen