Reposition the current line


You will often find yourself navigating a file that doesn’t entirely fit within your window’s viewport. The smaller your monitor and the larger your file, the more likely this will occur. In these cases, it might more comfortable to have the viewport shifted, moving the current line. With some quick key presses in normal mode, you can move your current line to the top, middle, or bottom of the screen as easy as so:

  • zt repositions the viewport so the current line is at the top, with one extra space above. (Just remember t for t op.)
  • zz repositions the viewport so the current line is in the middle.
  • zb repositions the viewport so the current line is at the bottom, with one extra space below. (Just remember b for b ottom.)

Here’s a quick screencast showing these in use:

First we move the current line to the top of the window with zt, then to the middle, with zz, then lastly to the bottom with zb. You can see how repositioning can be helpful to quickly expose portions above or below your working line.

How useful was this tip?

Average rating 3.6 / 5. Vote count: 350

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts