How do I switch between character, line, and block visual modes?
Answer
v, V, or Ctrl-V while in visual mode
Explanation
How it works
Vim has three visual modes, and you can switch between them without losing your current selection:
v- Characterwise visual mode (select individual characters)V- Linewise visual mode (select entire lines)Ctrl-V- Blockwise visual mode (select a rectangular block)
The key insight is that pressing any of these keys while already in a different visual mode will switch to that mode, keeping your selection anchor point. For example, if you start with v and select some characters, pressing V will switch to linewise selection covering the same lines.
Pressing the same key that you used to enter the current visual mode will exit visual mode entirely. So if you are in characterwise visual mode (v), pressing v again returns to normal mode.
This is especially useful when you start selecting in one mode and realize you need a different type of selection.
Example
Given this text:
foo bar baz
hello world
vim is great
- Place cursor on
bar, pressvto start characterwise visual - Press
jto extend selection down to the next line - Realize you want full lines -- press
Vto switch to linewise - Now both full lines are selected
- Or press
Ctrl-Vto switch to block mode for a rectangular selection
Each switch preserves the start and end points of your selection, just changing how the region between them is interpreted. This makes it easy to adjust your selection strategy on the fly without starting over.