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

How do I move the cursor to the other end of a Visual selection in Vim?

Answer

o (in Visual mode)

Explanation

When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored. Pressing o swaps the cursor to the opposite end of the selection, letting you adjust either boundary without losing what you've already selected.

How it works

  • Enter Visual mode (v, V, or <C-v>)
  • Make a selection by moving the cursor
  • Press o to jump the cursor to the other end of the selection
  • The selection stays intact — you can now extend or shrink from the opposite side
  • In Visual Block mode (<C-v>), use O to move to the other corner on the same line

Example

Given this text with the cursor on line 1:

alpha
beta
gamma
delta
  1. Press V to start line-wise Visual mode on "alpha"
  2. Press 2j to extend the selection down to "gamma"
  3. Realize you also need to exclude "alpha" — press o to jump the cursor to the "alpha" end
  4. Press j to shrink the selection to just "beta" and "gamma"

Tips

  • This is invaluable when you overshoot a selection and need to fix the starting boundary
  • In Visual Block mode, O toggles the cursor between the left and right corners of the current line
  • Works identically in character-wise (v), line-wise (V), and block-wise (<C-v>) modes
  • Combine with gv (reselect last Visual area) for rapid editing workflows

Next

How do I return to normal mode from absolutely any mode in Vim?