vi – changing case
As most system administrators, I use the vi text editor a ton in my job. So I am familiar with all the common commands you can run. Today I was wondering if it was possible to change lower case to upper case letters and the opposite, from upper case to lower case letters.
Here’s how you do it:
change all lower case to upper case (CAPITAL LETTERS):
:%s/^.*$/\U&/g
change all upper case to lower case (small letters):
:%s/^.*$/\L&/g
Of course, the % is the entire document, the s///g is search and replace the entire line, ^.*$ matches everything, and the important part \L& converts to lower case and \U& converts to upper case.
|
|
|
|
|
|
|
|
|
|
|
|
Awesome! Thanks! This is exactly what I was looking for.
Posted September 29, 2010, 12:28 pmthanks…I don’t do this often enough and between times I just forget.
Posted January 19, 2012, 7:09 pmKent – Thanks, that’s exactly why I post it!
Posted January 19, 2012, 11:51 pm