Kurt Keller's Blog

tech notes and more

move around the screen

The most basic commands to move up and down in vim are j and k. They are fine if you want to move line by line, but not if you want to move in larger steps. There are various commands to scroll the screen in bigger chunks.

CTRL-b  PgUp  SHIFT-Up scroll one screen backward (up)
CTRL-f  PgDown  SHIFT-Down scroll one screen forward (down)
CTRL-u scroll half a screen backward (up)
CTRL-d scroll half a screen forward (down)
CTRL-y scroll one line backward (up)
CTRL-e scroll one line forward (down)

I have memorized CTRL-f and CTRL-b, that’s sufficient for me. If I want to move half screens or single lines I do it differently, using a set of commands which I know anyways because they are very handy in certain situations.

Very often I want to quickly move the cursor to the top, bottom or middle of the current screen and then use j and h to go a certain line. There are three very handy commands for this.

H move the cursor to the top of the current screen (Head)
M move the cursor to the middle of the current screen (Middle)
L move the cursor to the bottom of the current screen (Last)

But when I’m writing scripts, I usually want the cursor to stay on the line it is at when scrolling up or down. Here a few z commands come in handy.

zt move the current line to the top of the screen, leaving the cursor on the current line (top)
zz move the current line to the center of the screen, leaving the cursor on the current line (zenter)
zb move the current line to the bottom of the screen, leaving the cursor on the current line (bottom)

These commands leave the cursor exactly where it was in the line. There is an equivalent set of z commands which additionally move the cursor to the first non-blank character of the line. But quite honestly, if I really want to do that there are other ways to achieve it and I rather remember fewer commands and type a little bit more than trying to remember every possibility and get confused.

Share

Leave a Reply