How do I progressively expand or contract a visual selection by text objects?
Answer
v3aw
Explanation
In visual mode, repeating text object motions progressively expands the selection. You can use counted text objects to select exactly the scope you need — from a word to a sentence to a paragraph — all within a single visual selection.
How it works
v— enter visual modeaw— select a word (including surrounding space)as— expand to select a sentenceap— expand to select a paragraph- Count prefix:
v3awselects 3 words at once o— jump cursor to other end of selection to adjust
Example
Text: The quick brown fox jumps over the lazy dog.
Cursor on 'brown':
viw → 'brown'
vaw → 'brown '
v3aw → 'brown fox jumps '
vas → 'The quick brown fox jumps over the lazy dog.'
Tips
- Use
oto toggle which end of the selection you're extending - In visual mode, pressing
iw,aw,i(,a(etc. adjusts the selection gnselects the next search match and can be expanded withn- Treesitter in Neovim provides
incremental_selectionfor syntax-aware expansion