Vim Uppercase & Lowercase
Posted on August 29th, 2007 in Everyday Tips, Ubuntu, Vim | 7 Comments »

I have been using vim for a couple years and every week it seems I learn some new feature or trick you can do. Recently I learned how to convert a selection to either all uppercase or all lowercase letters.
Convert a visual selection to all uppercase letters.
gU
Convert to lowercase letters
gu
7 Responses
Hi,
Just noticed this. Thanks for the tip, but the command doesn’t have a : prefix. Just use it as directed but without :
This also works if you don’t have a selection. For example, uppercase until the end of the word:
gUw
Or, two words:
gU2w
Or, end of the line:
gU$
Or, next 10 characters:
gU10l
Hi,
to change all UPPERCASE letters to lowercase letters in a file:
:%s/[A-Z]/\L&/g
nice!
@Jakub : it’s easier to just convert the whole file in lowercase :
1gguG
>Jakub Bielaszka Says:
>
>Hi,
>
>to change all UPPERCASE letters to lowercase letters in a file:
>
>:%s/[A-Z]/\L&/g
or guGG
To toggle between cases, you can use the ~ character.
In Command mode, it toggles the character under the cursor and in Visual mode it toggles the highlighted text.