Vim Tip of the Day: Quantifiers

Usually, Vim’s linguistic commands operate on a context inferred from the position of the cursor. But sometimes you may want to provide additional context for the operation. E.g. not this word but these words. Vim allows you to do this via quantifiers or “counts.”

d2w = delete two words
d3b = delete the three preceding words
c2} = change two paragraphs
c2t. = change un(t)il the second period [we’ll learn more about t soon]
3j = go down three lines

You can supply the quantifier either before or after the verb. E.g. 2ct. also works. That is, verb-quantifier-noun and quantifier-verb-noun are essentially equivalent.

Note that going into insert mode and back into normal mode is treated as a single command in Vim. So you can also do:

20ianybody there? [hit Esc]
10i<item></item>[hit Enter][hit Esc]

✨ Bonus: Replace mode ✨

R takes you into replace mode — it’s a quicker option in cases where you want to replace part of a word with something else of the same length. Try it!

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *