2

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
5

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
  • 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 Jan 6 '15 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

2
  • 2
    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. – Keith Thompson Jan 9 '14 at 23:03
  • 1
    You are right. These are alternative to Meta-r in Emacs. – Sergo Pasoevi Nov 7 '16 at 8:00
1

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-.

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.