Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thanks to you and @Klaus for the suggestion. I didn't know about \zs and \ze. However, %s/section{\zs\w\(.\)/\u&/gc doesn't do what I was trying to do. The \zs causes the uppercase replacement to take place on the first character after section{, but that is the only thing that matches. The g on the end of the line does not cause subsequent words on the line to be uppercased. I assume this is because as far as Vim is concerned, there is only one match on the line: The one that begins with "section{". I will continue experimenting, though. Commented Mar 20, 2019 at 2:43
  • \w in the preceding comment should be \<, but the same comment applies. Commented Mar 20, 2019 at 2:51
  • OK, I have figured out a solution: :g/section{/s/[^{\\]\zs\<\(.\)/\u&/gc . The g/section/ is needed because I want to do this only on the "section{" lines, but "section{" should not be involved in the replacement match. Then [^{\\]\zs means that I don't try to replace after the initial "\" on the line, nor after the "{" (since I already have an uppercase character after the brace), but then start searching for word-beginnings after that. The \zs is needed because otherwise the [^{\\] causes the interword space to be what's matched and then "uppercased", which would cause no change. Commented Mar 20, 2019 at 3:09
  • @Mars yes i do see how that’s a problem. Im going to edit my answer to use your solution, but I would consider Mass’s: it’s quite good. Commented Mar 20, 2019 at 3:16