VI make every first letter that comes after a underscore uppercase

4

3

Found this site:

And it works for the first character but my lines are line this

this_is_a_string

And I would like this

This_Is_A_String

Any thoughts?

VI Command would be nice but any other simple solution would work as well

Phill Pafford

Posted 2012-02-16T18:14:16.487

Reputation: 245

Answers

8

do :%s/^./\U&/ then :%s/_./\U&/g

the first will uppercase the first letter of every line, the second will uppercase the first letter after each underscore in all lines.

Rob

Posted 2012-02-16T18:14:16.487

Reputation: 2 152

3

Combining the two search/replace Rob suggested:

:%s/^.\|_./\U&/gc

will search for either the first char in a line or the first char following an _.

Explanation:

  • \| specifies 'or'
  • g will change all occurrences in a line
  • c will ask for confirmation

broomdodger

Posted 2012-02-16T18:14:16.487

Reputation: 1 810