4

There's a neat Control-L hotkey in Emacs that repetitively moves the cursor to the top/middle/bottom of the screen. I'm quite sure there's a vim equivalent for that, but I couldn't find it.

0

3 Answers 3

8

As an alternative, you can use the vim commands that refer to scrolling relative to cursor. Some of them have the advantage of leaving the cursor at the same column of the originating line. From the vim help (:help zz):

z Redraw, line [count] at top of window (default cursor line). Put cursor at first non-blank in the line.

zt Like "z", but leave the cursor in the same column. {not in Vi}

z{height} Redraw, make window {height} lines tall. This is useful to make the number of lines small when screen updating is very slow. Cannot make the height more than the physical screen height.

z. Redraw, line [count] at center of window (default cursor line). Put cursor at first non-blank in the line.

zz Like "z.", but leave the cursor in the same column. Careful: If caps-lock is on, this command becomes "ZZ": write buffer and exit! {not in Vi}

z- Redraw, line [count] at bottom of window (default cursor line). Put cursor at first non-blank in the line.

zb Like "z-", but leave the cursor in the same column. {not in Vi}

1
  • 2
    To make this answer more concise, type zt to redraw with the cursor top, zb to redraw with the cursor bottom, zz to redraw with the cursor middle. The <C-l> command in Emacs cycles though zz, zt, zb.
    – dreta
    Commented Jan 6, 2015 at 11:57
3

There is an equivalent - for both vi and vim :

H for top

M for middle and

L for the bottom of the screen

3
  • 3
    That's not equivalent. vim's H, M, and L keep the same text on the screen, just moving the cursor to the appropriate line in the file. The emacs Control-L keeps the cursor on the same line in the file, shifting the portion of the file that you're seeing (like vim's various z commands mentioned in Luis's answer. Commented Jan 9, 2014 at 23:03
  • 1
    You are right. These are alternative to Meta-r in Emacs. Commented Nov 7, 2016 at 8:00
  • Thank you for the correction, still useful information though that can be combined with the right answer!
    – mcp
    Commented Nov 29, 2021 at 17:17
3

Luis's answer above is correct, but the description in vim's help is a little bit unclear without a bit of experimentation. I am posting here the results of that experimentation.

To move the line that the current cursor is on to the top of screen, we need z-<CR>, which is typing z followed by [Enter] on the keyboard.

To move the line that the current cursor is on to the middle of the screen, we use zz.

To get the last behavior of C-L, we use z-.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .