sgur
7/1/2013 - 7:38 AM

<C-s> で値トグル

<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>