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

How do I move the cursor to the other corner of a visual block selection?

Answer

o and O

Explanation

In visual-block mode (<C-v>), pressing o moves the cursor to the diagonally opposite corner of the selection, and O moves it to the other end of the same row (flipping the selection left-right). These two keys let you extend or shrink a rectangular selection from any of its four corners without leaving visual mode.

How it works

  • <C-v> — enter visual-block (column) mode
  • o — jump to the opposite corner (diagonal flip: top-left ↔ bottom-right)
  • O — jump to the other end of the current row (horizontal flip: left ↔ right)

Both keys reposition the active end of the selection — the end the cursor is on — while keeping the anchor fixed. The block is always defined by the rectangle between the cursor and the anchor.

Example

Suppose you select a block starting from column 3, row 1 (top-left), extending to column 8, row 4 (cursor, bottom-right):

Line 1:  [foo bar]
           ^^^^^^^
Line 2:  [baz qux]
Line 3:  [aaa bbb]
Line 4:  [ccc ddd]

Pressing o moves the cursor to the top-left corner. Now you can extend the selection upward or leftward while keeping the bottom-right anchor fixed.

Pressing O (instead of o) moves the cursor to the bottom-left corner, letting you narrow or widen the block horizontally.

Tips

  • o works the same way in character-wise (v) and line-wise (V) visual modes — it always toggles the cursor between the two ends of the selection
  • After jumping corners with o, you can use motions normally to extend the selection from the new anchor point
  • Combining o and O lets you fine-tune all four edges of a block without ever canceling and re-entering visual mode

Next

How do I programmatically set a register's content in Vimscript to pre-load a macro?