Tip: vi and lowercase/uppercase
Submitted by lefred on Thu, 01/10/2008 - 13:32
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 ;)
Tags:















12 reponses to "Tip: vi and lowercase/uppercase"
1. Good tips, an easier
Good tips, an easier technique so far. A quick help that covers all of the important commands. - Jeffrey Nimer
2. Very useful . Thanks a lot
Very useful . Thanks a lot :-)
3. Thanks this helps :)
Thanks this helps :)
4. Thank you
It is neat stuff
5. thanks
Simple tip, but it juste saved my day :D
Thanks alot!
6. Help! Need driver for phillips wireless pcmcia card.
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
7. might be easier...
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
8. Anonymous is right!
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!
9. that last one in brackets there...
was supposed to be gU2<down arrow>
10. the 3rd "g"
You can think of the third "g" as "global"... as in "apply this to the whole file".
11. To my understanding, "apply
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?
12. Very clear
I didn't know what the 3rd g meant. Now I know. Thanks!