Vim Recipes ‣ Editing ‣ Changing the Case of Text
You want to change the case of a character or block of text. For example, you may want to change bob to Bob.
As normal, these commands accept motions. For example:
To convert a string to title case, i.e. initial capitals, you can
use the following regular
expression: s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g. Select the text you want to convert, hit
:, then enter the regular expression. If you use this regularly,
consider remapping a
key to execute this command. For example:
nnoremap <F7> :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g<CR>
vnoremap <F7> :s/\%V\(\w\)\(\w*\)\%V/\u\1\L\2/g<CR>