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
oto 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>), useOto move to the other corner on the same line
Example
Given this text with the cursor on line 1:
alpha
beta
gamma
delta
- Press
Vto start line-wise Visual mode on "alpha" - Press
2jto extend the selection down to "gamma" - Realize you also need to exclude "alpha" — press
oto jump the cursor to the "alpha" end - Press
jto 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,
Otoggles 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