Vim: Convert Upper to Lowercase - Editors

This is a discussion on Vim: Convert Upper to Lowercase - Editors ; Hi there, I'm trying to convert the case in certain lines in vi, but the search pattern I'm trying is not working! For example: :%s/[A-Z]/[a-z]/g converts "The Quick Dog" to "[a-z]he [a-z]uick [a-z]og" .... Not exactly the outcome I was ...

+ Reply to Thread
Results 1 to 6 of 6

Vim: Convert Upper to Lowercase

  1. Default Vim: Convert Upper to Lowercase

    Hi there,

    I'm trying to convert the case in certain lines in vi, but the search
    pattern I'm trying is not working!

    For example:

    :%s/[A-Z]/[a-z]/g

    converts "The Quick Dog" to "[a-z]he [a-z]uick [a-z]og" ....


    Not exactly the outcome I was hoping for :-)

    Is there anyway to do this within vi without resorting to a commandline
    sed/tr ?

    Thanks!


  2. Default Re: Vim: Convert Upper to Lowercase

    awayinlondon@googlemail.com <awayinlondon@googlemail.com> wrote:
    > I'm trying to convert the case in certain lines in vi, but the search
    > pattern I'm trying is not working!
    >
    > For example:
    >
    >:%s/[A-Z]/[a-z]/g
    >
    > converts "The Quick Dog" to "[a-z]he [a-z]uick [a-z]og" ....


    That can't work. The rhs is take as a string, not as a pattern. To
    make text lowercase use ``gu'' or ``gugu''

    :h gu
    :h gugu

    or for uppercase

    :h gU
    :h gUgU

    > Thanks!


    HTH
    ../otto

  3. Default Re: Vim: Convert Upper to Lowercase

    awayinlondon@googlemail.com wrote:

    > I'm trying to convert the case in certain lines in vi, but the search
    > pattern I'm trying is not working!


    > For example:


    >:%s/[A-Z]/[a-z]/g


    > converts "The Quick Dog" to "[a-z]he [a-z]uick [a-z]og" ....


    > Not exactly the outcome I was hoping for :-)


    But you asked for it :-)

    > Is there anyway to do this within vi without resorting to a commandline
    > sed/tr ?


    You could use the special \L combonation to indicate that the following
    character must be made lower case:

    :%s/[A-Z]/\L&/g

    Here you match any character in [A-Z]. The replacement string is then \L
    followed by &, which is short for what was matched in the left hand
    side.

    Peppe
    --
    se nocp cpo=BceFsx!$ hid bs=2 ls=2 hls ic " P. Guldberg /bin/vi@wielders.org
    se scs ai isf-== fdo-=block cino=t0,:0 hi=100 ru so=4 noea lz|if has('unix')
    se sh=/bin/sh|en|syn on|filetype plugin indent on|ono S V/\n^-- $\\|\%$/<CR>
    cno <C-A> <C-B>|au FileType vim,mail se sw=4 sts=4 et|let&tw=72+6*(&ft=~'v')

  4. Default Re: Vim: Convert Upper to Lowercase

    Preben 'Peppe' Guldberg </bin/vi@wielders.org> wrote:
    > You could use the special \L combonation to indicate that the following
    > character must be made lower case:
    >
    > :%s/[A-Z]/\L&/g
    >
    > Here you match any character in [A-Z]. The replacement string is then \L
    > followed by &, which is short for what was matched in the left hand
    > side.


    Oh yes, how could I forget about this. I think it's too hot in the
    office and I should go home

    > Peppe


    ../otto

  5. Default Re: Vim: Convert Upper to Lowercase

    awayinlondon@googlemail.com scripsit:
    >
    >:%s/[A-Z]/[a-z]/g
    >
    > converts "The Quick Dog" to "[a-z]he [a-z]uick [a-z]og" ....
    >


    In Vim:

    %s/[A-Z]/\l\0/g

    m.
    --
    LaTeX + Vim = http://vim-latex.sourceforge.net/
    Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
    vim.pl - http://skawina.eu.org/mikolaj
    CLEWN - http://clewn.sf.net

  6. Default Re: Vim: Convert Upper to Lowercase

    This info is just what I needed, thanks folks.

    I'm thinking somebody might want to replace words or identifiers in some particular context, maybe all occurrences of foo.BAR with foo.bar and FOO.BAR with FOO.bar (but not foo.bar) for example:

    %s/\.[A-Z_]\+/\L&/g

    the point is the LHS doesn't have to only match one char, and the \L& will still change whatever was matched to lower case, in this case only if the identifier is preceded by a period, and it won't mess with the _.

    -George

+ Reply to Thread

Similar Threads

  1. check and convert lower character to upper character
    By Application Development in forum c++
    Replies: 3
    Last Post: 11-18-2007, 06:28 AM
  2. Make first letter in string upper case, the rest in lowercase
    By Application Development in forum Java
    Replies: 7
    Last Post: 04-10-2007, 08:50 AM
  3. [IDCS2-PC] PMString - convert to upper case
    By Application Development in forum Adobe Indesign
    Replies: 1
    Last Post: 02-01-2007, 05:12 AM
  4. Convert lowercase to uppercase on incremental Variable String
    By Application Development in forum Clarion
    Replies: 4
    Last Post: 03-28-2006, 10:51 PM