Capitalizzazione parole
Preso da Fun with case twiddling
Someone came on #vim asking about "sentence case", meaning Capitalization Of Every Word.
I came up with some bad solutions before learning this:
:s/\(^\|\s\)\([a-z]\)/\1\U\2/g
This inspired me to come up with a silly script for rotating between ALL CAPS, all lower, and Sentence Case.
MiXed Case is set to UPPER.
Then I mapped it (in visual mode) to ~, thus breaking the wonderful tilde :)
Here's the script:
fun! TwiddleCase(str) if a:str == toupper(a:str) let ans = tolower(a:str) elseif a:str == tolower(a:str) let ans = substitute(a:str,"\\(^\\|\\s\\)\\([a-z]\\)","\\1\\U\\2","g") else let ans = toupper(a:str) endif return ans endfun
And the mapping:
vmap ~ x:call setreg('"', TwiddleCase(getreg('"')))^MP
Found an easier way to upper / lower case the whole file/part file.
do a visual select of the lines you want to do the modifications and gU ==> uppercase and gu ==> lowercase