How to move screen without moving cursor in Vim?

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?


  • 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

  • Additionally:

  • Ctrl-y Moves screen up one line
  • Ctrl-e Moves screen down one line
  • Ctrl-u Moves cursor & screen up ½ page
  • Ctrl-d Moves cursor & screen down ½ page
  • Ctrl-b Moves screen up one page, cursor to last line
  • Ctrl-f Moves screen down one page, cursor to first line
  • Ctrl-y and Ctrl-e only change the cursor position if it would be moved off screen.

    Courtesy of http://www.lagmonster.org/docs/vi2.html


    Vim要求光标始终处于当前屏幕中,但是,您可以将当前位置标记为书签,然后返回到原来的位置。

    mg  # This book marks the current position as g (this can be any letter)
    <scroll around>
    `g  # return to g
    
    链接地址: http://www.djcxy.com/p/8708.html

    上一篇: JavaScript:案例

    下一篇: 如何在不移动光标的情况下移动屏幕?