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.
3 Answers
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}
-
2To 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.– dretaCommented Jan 6, 2015 at 11:57
There is an equivalent - for both vi
and vim
:
H
for top
M
for middle and
L
for the bottom of the screen
-
3That's not equivalent.
vim
'sH
,M
, andL
keep the same text on the screen, just moving the cursor to the appropriate line in the file. Theemacs
Control-L
keeps the cursor on the same line in the file, shifting the portion of the file that you're seeing (likevim
's variousz
commands mentioned in Luis's answer. Commented Jan 9, 2014 at 23:03 -
1You 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!– mcpCommented Nov 29, 2021 at 17:17
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-
.