How do I title-case every word in a buffer using one Vim substitution?
Answer
:%s/\v<(\w)(\w*)>/\u\1\L\2/g
Explanation
When you need to normalize casing across headings, labels, or generated docs, editing words one by one is tedious. This substitution converts each word to title case in a single pass: first letter uppercase, remainder lowercase. It is a practical cleanup step after importing noisy text from external tools.
How it works
:%s/\v<(\w)(\w*)>/\u\1\L\2/g
:%stargets the whole buffer\venables very-magic regex syntax<(\w)(\w*)>matches each word boundary and splits the word into first character plus remainder\u\1uppercases capture group 1 (the first letter)\L\2lowercases capture group 2 (the rest of the word)gapplies this to every word occurrence on each line
Example
Before:
ERROR LEVEL summary
second LINE OF TEXT
After:
Error Level Summary
Second Line Of Text
Tips
- To avoid touching short acronyms, run with
cand confirm selectively - Restrict the range (for example
:10,40s/...) when you only want part of a file normalized - Combine with marks so you can jump back to your original editing location quickly