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.





Please VOTE for this page at: ADD TO DEL.ICIO.US | ADD TO DIGG | ADD TO FURL | ADD TO NEWSVINE | ADD TO NETSCAPE | ADD TO REDDIT | ADD TO STUMBLEUPON | ADD TO TECHNORATI FAVORITES | ADD TO SQUIDOO | ADD TO WINDOWS LIVE | ADD TO YAHOO MYWEB | ADD TO ASK | ADD TO GOOGLE


5 Comments


  1. Awesome! Thanks! This is exactly what I was looking for.

    Posted September 29, 2010, 12:28 pm

  2. thanks…I don’t do this often enough and between times I just forget.

    Posted January 19, 2012, 7:09 pm

  3. Kent – Thanks, that’s exactly why I post it!

    Posted January 19, 2012, 11:51 pm

  4. this may be a vi/vim version issue, but with actually need to escape the L or U in the replace portion:

    :%s/^.*$/\L&/g
    :%s/^.*$/\U&/g

    Posted November 2, 2012, 3:17 pm

  5. The example posted in the original post does not work for my version of vi. It only adds an “L” to the beginning of each line.

    The commands mike posted did the trick for me.

    Posted May 30, 2013, 9:34 pm

Leave a reply