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

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 mode
  • aw — select a word (including surrounding space)
  • as — expand to select a sentence
  • ap — expand to select a paragraph
  • Count prefix: v3aw selects 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 o to toggle which end of the selection you're extending
  • In visual mode, pressing iw, aw, i(, a( etc. adjusts the selection
  • gn selects the next search match and can be expanded with n
  • Treesitter in Neovim provides incremental_selection for syntax-aware expansion

Next

How do I return to normal mode from absolutely any mode in Vim?