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

How do I move the cursor to the other end of a visual selection to adjust it?

Answer

v_o

Explanation

When you start a visual selection, the cursor is at one end and the anchor is at the other. If you realize you need to extend the selection in the opposite direction, pressing o in visual mode swaps the cursor to the other end without losing the selection. This is essential for efficiently adjusting selections that you started from the wrong position.

How it works

  • v, V, or <C-v> — enter any visual mode
  • Select some text by moving the cursor
  • o — jump the cursor to the opposite end of the selection
  • Now you can extend or shrink the selection from the other side
  • In visual block mode (<C-v>), O (uppercase) moves to the other corner on the same line

Example

Suppose you visually select lines 5-10 but realize you need lines 3-10:

  line 3   <-- need to include this
  line 4   <-- and this
| line 5   <-- cursor anchor (start of selection)
  ...
  line 10  <-- cursor is here

Press o to jump to the top of the selection (line 5), then press kk to extend upward to line 3. The bottom of the selection stays at line 10.

Tips

  • Works in all three visual modes: characterwise (v), linewise (V), and blockwise (<C-v>)
  • In blockwise mode, O moves the cursor to the other corner horizontally while o moves vertically
  • This is far more efficient than re-selecting when you overshoot or start from the wrong position

Next

How do I ignore whitespace changes when using Vim's diff mode?