->Title Page
->Intro
->Unix
->Vi editor
-->Basics
-->Vi reference
-->Miscellaneous tips
--->Line deletions
->Switching cases
--->Spell checking
--->Advanced S and R
--->Blank lines
--->Buffers
->Mirror sites
->Further reading

[ Up ]
[Prev][Home][Next]
[Author]

Vi ---> Switching cases

In the replacement part of a substitution command, i.e. between the second "/" and third "/",


    \u means make the following character upper case
    \l means make the following character lower case
    \U means make the rest of the replacement upper case
    \L means make the rest of the replacement lower case
How about a few examples?

  1. Make the first letter of every word from line 18 to 43 uppercase.

    
        :18,43s/\<./\u&/g
  2. Change "uPPeR" and "LoweR" in any mixture of cases to lowercase.

    
        :s/[UuLl][PpOo][PpWw][Ee][Rr]/\L&/
  3. Make the whole file uppercase.

    
        :%s/.*/\U&/
  4. Make the region from line m to line n all uppercase.

    
        :'m,'ns/.*/\U&/
  5. Make a paragraph all lowercase.

    
        :?^$?,/^$/s/.*/\L&/
  6. Make the first letter of every word in a paragraph uppercase.

    
        :?^$?,/^$/s/\([^ ][^ ]*\)/\u&/g
  7. Make the second word of each line uppercase.

    
        :1,$s/^\([^ ]*\) \([^ ]*\) \(.*\)/\1 \U\2\e \3/

Please notify owners of webpages with outdated links to these pages

Find this site useful? Want to give something back?

© 1993-2001 Christopher C. Taylor