Created
September 26, 2011 13:23
-
-
Save bootleq/1242220 to your computer and use it in GitHub Desktop.
Old way to toggle words, I no longer use it.
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
" }}}2 ToggleTextOption {{{2 | |
" http://vim.wikia.com/wiki/Toggling_yes-no | |
function! ToggleTextOption() | |
let w = expand("<cword>") | |
call RegStash(1, '"') | normal yl | |
let c = @" | call RegStash(0, '"') | |
let pairs = [ | |
\ ["true", "false"], | |
\ ["0", "1"], | |
\ ["yes", "no"], | |
\ ["on", "off"], | |
\ ["and", "or"], | |
\ ["??, "??], | |
\ ["show", "hide"], | |
\ ["left", "right"], | |
\ ["before", "after"], | |
\ ["absolute", "relative"], | |
\ ["decode", "encode"], | |
\ ["asc", "desc"], | |
\ ["define", "undef"], | |
\ ["exclude", "include"], | |
\ ["if", "unless"], | |
\ ["blank", "present"], | |
\ ["while", "until"], | |
\ ["first", "last"], | |
\ ["in", "out"], | |
\ ["get", "post"], | |
\ ["to", "from"], | |
\ ["only", "except"], | |
\ ["foreign_key", "primary_key"], | |
\ ["inspect", "to_yaml"], | |
\ ["add_column", "remove_column"], | |
\ ] | |
let c_orig = c | |
if c=="+" | let c="-" | |
elseif c=="-" | let c="+" | |
elseif c=="<" | let c=">" | |
elseif c==">" | let c="<" | |
else | let c="" | |
endif | |
if c != "" | |
exec "normal r" . c | |
return | |
else | |
let c = c_orig | |
endif | |
if match(w, c) >= 0 " cursor should not under a keyword | |
for pair in pairs | |
if w == pair[0] | |
let w = s:ToggleTextOption_caseToggle(w, pair[1]) | |
break | |
elseif w == pair[1] | |
let w = s:ToggleTextOption_caseToggle(w, pair[0]) | |
break | |
endif | |
endfor | |
if w != "" && w != expand('<cword>') | |
call PosStash(1) | |
exec "normal! \"_ciw\<C-R>=w\<CR>\<Esc>" | |
call PosStash() | |
endif | |
endif | |
endfunc | |
fun! s:ToggleTextOption_caseToggle(in, out) | |
if a:in =~ '^\u*$' | |
return toupper(a:out) | |
elseif a:in =~ '^\u' | |
return toupper(strpart(a:out, 0, 1)) . strpart(a:out, 1) | |
else | |
return a:out | |
endif | |
endf | |
" nnoremap <silent> <LocalLeader>a :call ToggleTextOption()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment