From 796ffd9e34bd5208048d1b5062c09022ed57de62 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Mon, 29 Sep 2025 14:56:19 +0200 Subject: [PATCH] Toggle casing --- .vimrc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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