diff --git a/.vimrc b/.vimrc index 7f8c38a..481cd4c 100644 --- a/.vimrc +++ b/.vimrc @@ -586,6 +586,21 @@ fun! TrimWhitespace() endfun command! TrimWhitespace call TrimWhitespace() +" Visually select text then press ~ to convert the text to UPPER CASE, then to lower case, then to Title Case. +" Keep pressing ~ until you get the case you want. +" https://vim.fandom.com/wiki/Switching_case_of_characters +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 +vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))gv""Pgv + " enable words completion set dictionary+=/usr/share/dict/words " use ctrl-n ctrl-n instead of ctrl-x ctrl-k