TIL: Vim Text Objects
Last updated: 2/5/2025
Most vim commands take text objects. For instance, we can do diw for delete in word or daw for delete around word, which includes the delimiters as well. I use w pretty heavily to select alphanumeric words, but there’s actually a lot of other useful options:
W: whitespace-delimited words: sentencep: paragraph": contents within double quotes': contents within single quotes- ```: contents within backticks
(or): contents within parentheses[or]: contents within square brackets{or}: contents within curly brackets/braces<or>: contents within angle bracketst: contents within HTML tags like<a></a>
Two plugins supported by VSCodeVim implementation make this even more powerful:
- CamelCaseMotion.vim: Adds
\wfor camel-case and snake-case words. - surround.vim: Adds options for changing surrounding delimiters in addition to the contents inside.
- targets.vim: Adds smarter quote selection and separators like
*(only partially supported byVSCodeVim).