Last active
August 29, 2015 14:10
-
-
Save kmanalo/6ded920b681ec39041af to your computer and use it in GitHub Desktop.
twiddlecase.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" https://github.com/tangledhelix/dotfiles/blob/master/vim/plugin/twiddlecase.vim | |
" Toggles between uppercase, lowercase, titlecase. Bind to a mapping, then | |
" select something and keep hitting the map until you get what you want. | |
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 | |
" Example mapping | |
"vnoremap ~ ygv"=TwiddleCase(@")<CR>Pgv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment