Loading ...
Sorry, an error occurred while loading the content.

Re: switch the character case

Expand Messages
  • Stroller
    ... I find this useful, added to .vimrc: function! TwiddleCase(str) if a:str ==# toupper(a:str) let result = tolower(a:str) elseif a:str ==# tolower(a:str) let
    Message 1 of 3 , Feb 1, 2010
    • 0 Attachment
      On 1 Feb 2010, at 09:42, anna wrote:
      > ...
      > I want to a switch the character case of a string variable.
      > Is there a function to invert the character case, from lowercase to
      > uppercase and vice versa?


      I find this useful, added to .vimrc:

      function! TwiddleCase(str)
      if a:str ==# toupper(a:str)
      let result = tolower(a:str)
      elseif a:str ==# tolower(a:str)
      let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
      else
      let result = toupper(a:str)
      endif
      return result
      endfunction
      map <F6> ygv"=TwiddleCase(@")<CR>Pgv

      From: http://vim.wikia.com/wiki/Switching_case_of_characters

      Stroller.

      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.