Pacific-Design.com

    
Home Index

1. Vim

2. Case

Vim / Case /

Convert all the first letter of words to upper case and the rest to lower case.

:%s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g

Convert to Upper Case

CTRL+V
U

Convert to Lower Case

CTRL+V
u

vi ~/.vimrc : [press ~] to convert the text to UPPER CASE, lower case and Title Case


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 ~ ygv"=TwiddleCase(@")Pgv