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

How do I jump to the Nth line from the top or bottom of the visible screen using a count with H and L?

Answer

{count}H and {count}L

Explanation

Most Vim users know H jumps to the first visible line, M to the middle, and L to the last. What fewer know is that H and L both accept a count prefix: {N}H jumps to the Nth line from the top of the visible screen, and {N}L jumps to the Nth line from the bottom. This gives precise, screen-relative navigation without counting or using line numbers.

How it works

  • H — jump to the first line of the visible screen (Home)
  • {N}H — jump to the Nth line from the top (counting from 1)
  • L — jump to the last visible line
  • {N}L — jump to the Nth line from the bottom (counting from 1)
  • M — jump to the middle of the visible screen (no count variant)

The count begins at 1, so 1H equals plain H and 1L equals plain L.

Example

If your screen currently shows lines 80–130:

Line 80   ← H (or 1H)
Line 82   ← 3H
Line 105  ← M
Line 128  ← 3L
Line 130  ← L (or 1L)

Tips

  • Combine with operators: d5H deletes from the current line to 5 lines from the top
  • y3L yanks from the current line down to 3 lines from the bottom
  • Useful when you can see the target line and want to jump there without :N or counting
  • After jumping, zz repositions the view if needed
  • See :help H and :help L for full documentation

Next

How do I open the command-line window mid-command to edit it with full Vim capabilities?