I would like to know the proper substitution command in vi that would accomplish this.

  • Did you meant capitalizying the first word or first character of the first word?
    – SibiCoder
    Sep 24, 2016 at 14:59

1 Answer 1


This is a normal vim substitute command with ; as separation character; you can use other characters beside the default / as separation character, as long as it does not appear in the expression.

%s        : Do substitute command on the entire buffer

[.?!]     : match every . or ? or ! and
\_s*      : match every whitespace including newline after it if there is any, and
\zs       : start the match from here and
\<\w\+\>  : select first word

\U&       : then make it capitalize (or use \u& to only capitalize first character)

g         : globally
  • What do the semi colons represent? Sep 23, 2016 at 0:44
  • 4
    @JohnBradowski, one can use other delimiters like ; # instead of usual /
    – Sundeep
    Sep 23, 2016 at 3:57
  • 2
    There is often a space between a punctuation mark and the following word, so your command could be %s;[.?!]\s\?\<\w\+\>;\U&;g to handle these white-spaces.
    – statox
    Sep 23, 2016 at 9:05
  • 1
    @statox To be useful, you'd presumably also want the regexp to handle newlines, paragraph breaks, etc.
    – Rich
    Sep 23, 2016 at 9:29
  • @Sundeep, tanx for explanation. answer edited.
    – dNitro
    Sep 23, 2016 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.