Tip: vi and lowercase/uppercase

on
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

As always I use my blog as reminder of some useful commands or tips.

This one is for dimi, to change the case of a full document in vi, use the following command to transform everything in lowercase :


<ESC>:%s/.*/\L&/

and in uppercase :

<ESC>:%s/.*/\U&/

I hope this helps 😉

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

13 thoughts on “Tip: vi and lowercase/uppercase

  1. for uppercase: gggUG
    for lowercase: ggguG

    PS: the first 2 g’s are for moving to the beginning of the document.
    PS2: works in vim, don’t know about plain vi

    1. so just wanted to break down that last post so people know what’s up with it.

      the first 2 ‘g’s put your cursor to the beginning of the file. the 3rd g puts you in what appears to be a “replace” mode of some kind. U means uppercase (or u means lowercase) the final G means until the end of the file.

      So if you want to manipulate just a single word you should move the cursor to the beginning of the word then type gUw ((g)replace to (U)uppercase until (w)the end of the word).

      Or if you want to go from the current position to the end of the line gU$ ((g)replace to (U)uppercase until ($)the end of the line).

      Or if you want to go from the current position to the next ‘x’ on the line gUtx ((g) replace to (U) uppercase (t) to (x) the x character)… Of course you can replace x with any character you want.

      Figured that might help those who don’t know about jumping around in a file.

      (also if you only want to do the current line and the next two lines: gU2).

      This stuff is handy!

          1. To my understanding, “apply to the Whole file” is done by the last ‘G’ not the 3rd ‘g’.
            the ‘G’ means “till the end of the document”.

            The 3rd ‘g’ would mean “apply to all characters” and may be replace by a regexp, no?

  2. I need a driver for my phillips snn6500 wireless netcard
    or smc2632 wireless net card.
    I can`t make them run on linpus linux lite.

    Please help.

    Regards,
    VadeDromaro

  3. I had a similar problem: had a list of words, one in each line, and wanted to append a ‘;’ followed by the word in lowercase. Thanks for this page, it helped me find the solution:
    :%s/\(.*\)/\1;\L&/g

Leave a Reply

Your email address will not be published. Required fields are marked *

recent

Last Tweets Last Tweets

Locations of visitors to this page
categories