Monday, February 1, 2010

Re: switch the character case

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

No comments:

Post a Comment