How do I move the cursor to the horizontal midpoint of the current screen view?
Answer
gm
Explanation
The gm command moves the cursor horizontally to the middle of the current screen width on the current line. This is especially useful when :set nowrap is on and a long line extends beyond the visible area — gm snaps the cursor to the center column of the terminal, regardless of the line content.
How it works
gis a prefix for many screen-based motion commandsmmeans "middle" — specifically, the middle column of the current window's width- Unlike
M(which goes to the middle screen row),gmmoves horizontally within the current row - If the line is shorter than the middle column, the cursor lands at the last character
Example
With a terminal width of 80 columns and :set nowrap, given a 200-character line, placing the cursor at the start and pressing gm moves it to column 40 — the center of the visible window. Useful for quickly orientating yourself on a long line.
Tips
- Pair with
g0(start of screen line) andg$(end of screen line) for full screen-based horizontal navigation - Works in visual mode to extend selection to the screen midpoint
- Combine with
zHandzL(scroll half a screen width left/right) to navigate wide files efficiently gM(capital M) moves to the middle of the line content itself, not the screen