Note to self: Title Case in vim

Strictly as a note to myself, because I’ll never remember this on its own …

:s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g

That will convert a line of text to Title Case in vim, either on the line it’s issued or over selected blocks.

vim has single-key case conversion anyway (the tilde key) but this might be the quickest way to arbitrarily switch everything to title case.

Not my discovery or idea; found by way of the Vim Tips Wiki.

About these ads

2 thoughts on “Note to self: Title Case in vim

  1. Tim

    To be honest, I’d rather just do: ~w.w.w.w.w.w.w [...]

    It’s easier for me to mash the w and . keys than it is to find and copy in that regex monstrosity.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s