Skip to content

Instantly share code, notes, and snippets.

@kmanalo
Last active December 21, 2025 03:56
Show Gist options
  • Select an option

  • Save kmanalo/6ded920b681ec39041af to your computer and use it in GitHub Desktop.

Select an option

Save kmanalo/6ded920b681ec39041af to your computer and use it in GitHub Desktop.
twiddlecase.vim
" 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
@alanoakes
Copy link

Hello @kmanalo ,
I use this simple vim script A LOT every day in my vimrc for the past four years. Thank you very much for putting it in github for others to use!!

@kmanalo
Copy link
Author

kmanalo commented Dec 21, 2025

@alanoakes I read this earlier in the year and it was one of those I was intending to reply to you but I never did...

Take my reply back as a belated holiday gift and I sincerely with you the best in your endeavors!

image

I've been using a lot of vim, but I live in default land most of the time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment