How do I move the cursor to the other end of a visual selection without restarting it?
Answer
o (visual mode)
Explanation
In visual mode, pressing o swaps the cursor between the two ends of the selection (the anchor and the free end). The selection itself stays exactly as it is — you just reposition which end you're actively extending from. This lets you adjust either boundary of a selection without canceling and re-selecting.
How it works
- When you start a visual selection, the start point is the anchor and the cursor is the free end
- Pressing
ojumps the cursor to the anchor position, making it the new free end, while the original cursor position becomes the new anchor - You can then extend or shrink the selection from the other side
- Works in
v(characterwise) andV(linewise) visual modes
Example
You visually select a block by pressing v and moving down. You realize you started one line too late:
Step 1: Press v on line 3, extend to line 7 → cursor is at line 7
Step 2: Press o → cursor jumps to line 3 (the anchor)
Step 3: Press k → selection now starts at line 2, ends at line 7
Without o, you'd have to exit visual mode, reposition, and re-select.
Tips
- In
<C-v>(visual block) mode, useOinstead to move to the diagonally opposite corner of the block - Combine with
gv(reselect last visual selection) to recover and adjust a selection after accidentally pressing<Esc> - Works seamlessly with text objects: select
vipto grab a paragraph, thenoto jump to its top and extend upward