1
0
mirror of https://github.com/aquatix/dotfiles.git synced 2025-12-06 21:45:10 +01:00

Toggle casing

This commit is contained in:
2025-09-29 14:56:19 +02:00
parent 38751d075b
commit 796ffd9e34

15
.vimrc
View File

@@ -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(''))<CR>gv""Pgv
" enable words completion
set dictionary+=/usr/share/dict/words
" use ctrl-n ctrl-n instead of ctrl-x ctrl-k