How do I switch between visual mode and select mode in Vim?
Answer
v{motion}<C-g>
Explanation
Vim has a lesser-known select mode that behaves like selection in typical GUI editors: any typed character replaces the selection. You can toggle between visual mode and select mode using <C-g> while a selection is active. This is useful when you want to quickly replace a block of text by typing over it.
How it works
v{motion}— start visual mode and select text with any motion<C-g>— toggle from visual mode to select mode (or back)- In select mode, typing any printable character replaces the entire selection with that character and puts you in insert mode
- Press
<C-g>again to toggle back to visual mode
Select mode is essentially visual mode with "type-to-replace" behavior, making it feel more like a traditional text editor.
Example
Starting with:
The quick brown fox
- Press
veeto visually selectquick brown - Press
<C-g>to enter select mode - Type
slow red— the selection is replaced and you are in insert mode
Result:
The slow red fox
Tips
- Enter select mode directly with
gh,gH, org<C-h>(character, line, and block select modes) <C-o>in select mode executes one visual-mode command and returns to select mode- Useful in snippet/template systems where placeholders should be replaced by typing