Created
August 21, 2010 03:36
-
-
Save bootleq/541723 to your computer and use it in GitHub Desktop.
[.vimrc] toggle between CamelCased/under_scored word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" TODO when no keyword is under/after the cursor, try looking backward to find a word. | |
fun! WordTransform() | |
let w = expand("<cword>") | |
let x = '' | |
let c = strpart(getline('.'), col('.') - 1, 1) | |
if match(w, '_') > -1 | |
let x = substitute(w, '_\([a-z]\)', '\u\1', 'g') | |
else | |
let x = substitute(w, '\C[A-Z]', '_\L\0', 'g') | |
endif | |
if x == w | |
echohl WarningMsg | echomsg "Not a camelCased/under_scored word." | echohl None | |
return | |
endif | |
if match(w, c) < 0 " cursor might sit before keyword | |
exec "normal f" . strpart(w, 0, 1) | |
exec "normal \"_ciw\<C-R>=x\<CR>" | |
else | |
exec "normal \"_ciw\<C-R>=x\<CR>" | |
endif | |
endf | |
nnoremap <LocalLeader>x :call WordTransform()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment