207

Any quicker navigation trick to place the line at which the cursor is at the moment to the

  • top of the screen?
  • center of the screen?
  • bottom of the screen?

2 Answers 2

291

zEnter or zt puts current line to top of screen

z. or zz puts current line to center of screen

z- or zb puts current line to bottom of screen

(zEnter, z., and z- puts the cursor in the first non blank column. zt, zz, and zb leaves the cursor in the current column)

More info about scrolling at http://vimdoc.sourceforge.net/htmldoc/scroll.html or
in vim type :help scroll-cursor

4
  • 2
    I hadn't heard of z. before. I think I prefer having two different keys to hit rather than a double press. You can make parallel keystrokes concurrently, so long as they land in the right order, and the time between hits can be quite short, making this a very fast option. The z and . keys are mirrors of each other (at least on my en-GB keyboard). You could reasonably prefer a double tap of the z, and it's great we have both options. Apr 29, 2017 at 20:27
  • 3
    Also <line number>z<t | z | b> will put the line at line number at the top, center, or bottom of the vim buffer.
    – mljrg
    Feb 19, 2020 at 10:59
  • 1
    Check your scrolloff setting. These only put the line at the top or bottom of the screen if scrolloff=0, otherwise there are scrolloff lines before or after the cursor. If you type zz and the current line is not at the top, but there are lines above the current lines, type :se so=0. See vimdoc.sourceforge.net/htmldoc/options.html#'scrolloff'. Feb 20, 2020 at 12:46
  • Can't explain zztop command still doesn't exist, though :)
    – Obsidian
    Feb 13 at 19:30
28

Output of the :help scroll-cursor @mtk mentions. Note that there is a difference between zz and z..


Scrolling relative to cursor (scroll-cursor)

The following commands reposition the edit window (the part of the buffer that you see) while keeping the cursor on the same line:

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

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

z{height}<CR>           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}

Scrolling horizontally (scroll-horizontal)

For the following four commands the cursor follows the screen. If the character that the cursor is on is moved off the screen, the cursor is moved to the closest character that is on the screen. The value of 'sidescroll' is not used.

z<Right>    or
zl                      Move the view on the text [count] characters to the
                        right, thus scroll the text [count] characters to the
                        left.  This only works when 'wrap' is off.  {not in
                        Vi}

z<Left>      or
zh                      Move the view on the text [count] characters to the
                        left, thus scroll the text [count] characters to the
                        right.  This only works when 'wrap' is off.  {not in
                        Vi}

zL                      Move the view on the text half a screenwidth to the
                        right, thus scroll the text half a screenwidth to the
                        left.  This only works when 'wrap' is off.  {not in
                        Vi}

zH                      Move the view on the text half a screenwidth to the
                        left, thus scroll the text half a screenwidth to the
                        right.  This only works when 'wrap' is off.  {not in
                        Vi}

For the following two commands the cursor is not moved in the text, only the text scrolls on the screen.

zs                      Scroll the text horizontally to position the cursor
                        at the start (left side) of the screen.  This only
                        works when 'wrap' is off.  {not in Vi}

ze                      Scroll the text horizontally to position the cursor
                        at the end (right side) of the screen.  This only
                        works when 'wrap' is off.  {not in Vi}
1
  • Like my comment above; check scrolloff! zt and zb put scroll to scrolloff lines of the top and bottom. Type se so to see your setting and se so=0 to get the behavior in the answer above. Mar 29, 2021 at 23:43

You must log in to answer this question.

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