How do I move the cursor to the other end of a visual selection?
Answer
o (in visual mode)
Explanation
While in visual mode, pressing o swaps the cursor to the opposite end of the selection. This lets you expand or shrink either end of your selection without restarting it.
How it works
- In characterwise visual mode (
v):omoves the cursor between the start and end of the selection - In linewise visual mode (
V):omoves between the first and last selected line - In blockwise visual mode (
<C-v>):omoves diagonally to the opposite corner,Omoves to the other corner on the same line
Example
You start a visual selection from line 10, select down to line 20:
Line 10 (selection start)
...
Line 20 (cursor here)
Press o — cursor jumps to line 10. Now press k to extend the selection upward to line 9.
Press o again — cursor jumps back to line 20. Press j to extend downward to line 21.
Block mode: O vs o
In <C-v> block mode, a block has 4 corners:
A----B
| |
C----D
oswaps diagonally: A ↔ D, B ↔ COswaps horizontally: A ↔ B, C ↔ D
Tips
- This is essential when you selected from the wrong starting point
- Without
o, you'd have to cancel the selection and restart - Works seamlessly in all three visual modes
- Many users forget this feature exists and waste time restarting selections
- Documented under
:help v_o