vimtricks.wiki Concise Vim tricks, one at a time.

How do I move the cursor to the top of the visible screen?

Answer

H

Explanation

The H command moves the cursor to the first line of the currently visible screen (the "High" position). It does not scroll the viewport — it only repositions the cursor within what is already displayed.

How it works

  • H moves the cursor to the topmost line visible on the screen
  • The cursor lands on the first non-blank character of that line
  • With a count, 3H moves to the 3rd line from the top of the screen

Example

If your screen currently shows lines 50–90 of a file and your cursor is on line 75, pressing H moves the cursor to line 50 (the top of the visible area). The screen does not scroll.

Tips

  • Use M to move the cursor to the middle line of the screen
  • Use L to move the cursor to the last (bottom) line of the screen
  • These three commands (H, M, L) are extremely useful for quickly repositioning within the visible area without scrolling
  • Combine with operators: dH deletes from the current line to the top of the screen
  • Use zt to scroll so the current line appears at the top of the screen (different from H, which moves the cursor instead)
  • The scrolloff setting affects H — if scrolloff is set to 5, H will move to the 6th line from the top instead of the 1st

Next

How do I edit multiple lines at once using multiple cursors in Vim?