How do I move the cursor to the other end of a visual selection?
Answer
{Visual}o
Explanation
While in visual mode, pressing o moves the cursor to the opposite end of the selection. This lets you expand or contract the selection from the other anchor point without having to restart the selection entirely.
How it works
In visual mode, a selection always has two endpoints: a fixed anchor and the cursor. Normally, you can only extend the selection from the cursor's current position. Pressing o swaps which end is the anchor and which is the cursor, so you can immediately adjust the opposite boundary.
vorVor<C-v>— enter visual mode and begin a selectiono— jump the cursor to the other end of the selection (anchor becomes cursor, cursor becomes anchor)O— in visual block mode, moves to the other corner on the same line (toggles between the left and right corners of the current row)
Example
You visually select three lines downward and then realize you went one line too far at the start:
Line 1 ← you want the selection to start here
Line 2 ← selection actually starts here (anchor)
Line 3
Line 4 ← cursor is here
Press o to jump the cursor to Line 2 (the old anchor), then press k to move it up to Line 1. The selection now spans Line 1 through Line 4 with the correct boundaries.
Tips
- Works in all three visual modes: characterwise (
v), linewise (V), and blockwise (<C-v>) Oin visual block mode moves between the two corners on the same row, useful for adjusting the column span of a block selection- Combine with text-object expansions: select with
vip, presso, then extend from the top