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

How do I make Vim preserve the cursor column when jumping between lines?

Answer

:set nostartofline

Explanation

By default, many Vim movement commands — gg, G, Ctrl-d, Ctrl-u, Ctrl-f, Ctrl-b, and others — snap the cursor to the first non-blank character of the destination line. Setting nostartofline disables this behaviour and keeps the cursor in the same column whenever possible.

How it works

  • The startofline option (on by default) causes certain "large" motions to reposition the cursor to column 1 (or the first non-blank character) after the move
  • :set nostartofline turns this off: the cursor stays in whatever column it was in before the jump, clamped to the length of the destination line
  • Affected commands include: gg, G, H, M, L, Ctrl-d, Ctrl-u, Ctrl-f, Ctrl-b, %, {, }, and Ex commands like :N (jump to line N)
  • Normal word and character motions (w, b, j, k) are unaffected — they never used startofline anyway

Example

Given this file, with cursor at column 10 on line 1:

col:      ^cursor here
short
a longer line with more text

With default startofline, pressing } moves to line 3, column 1. With nostartofline, pressing } moves to line 3, column 10 (or the end of line 3, whichever is less).

Tips

  • Add set nostartofline to your vimrc for a permanent, column-aware navigation style
  • This is especially useful when working with structured data (CSV, aligned tables) where staying in a column is important
  • Some plugins and Vim internals still reset the column; this option only affects the listed motion commands

Next

How do I quit Vim without saving using a two-keystroke normal mode shortcut?