Skip to content

Instantly share code, notes, and snippets.

@sgur
Created July 1, 2013 07:38
Show Gist options
  • Save sgur/5899010 to your computer and use it in GitHub Desktop.
Save sgur/5899010 to your computer and use it in GitHub Desktop.
<C-s> で値トグル
" <C-s> で値トグル
" ----------------
function! s:toggle_value()
let pos = getpos('.')
let col = pos[2]
let line = getline('.')
if line[col-1] !~# '\i' | return | endif
let left = match(line, '\i*\%'.col.'c\i*')
let right = matchend(line, '\i\+', left-1)
let src = line[left : right-1]
for pattern in [['0', '1'], ['true', 'false'], ['TRUE', 'FALSE'], ['True', 'False']]
if src ==# pattern[0]
let dest = pattern[1]
elseif src ==# pattern[1]
let dest = pattern[0]
endif
endfor
if !exists('dest')
return
endif
let line = line[: left-1] . dest . line[right :]
call setline('.', line)
let pos[2] = left + len(dest)
call setpos('.', pos)
endfunction
nnoremap <silent> <C-s> :<C-u>call <SID>toggle_value()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment