Capitalize the First Letter of Every Word Using Vim Regex
To capitalize the first letter of each word in a sentence, use the following Vim command:
:s/\<\w/\u&/g
Explanation of the Command
-
:s/
starts the substitution command in Vim, which is used to find a pattern and replace it with a specified value. -
\<
matches the beginning of a word. In Vim, a word is defined as a sequence of letters, digits, or underscores. -
\w
matches any word character (letters, digits, or underscores). -
\u
is a replacement flag in Vim that converts the next character in the replacement string to uppercase. -
&
represents the entire matched text from the search pattern (in this case, the first character of each word). -
/g
applies the substitution globally, ensuring every matching occurrence in the line is processed rather than just the first one.
By running this command, Vim will capitalize the first letter of each word in the specified text.
Top comments (0)