Skip to content

Instantly share code, notes, and snippets.

@saihoooooooo
Created December 8, 2011 03:37
Show Gist options
  • Save saihoooooooo/1445997 to your computer and use it in GitHub Desktop.
Save saihoooooooo/1445997 to your computer and use it in GitHub Desktop.
toggle option function
nnoremap [Option] <Nop>
nmap xo [Option]
nnoremap <silent>[Option]n :<C-u>call <SID>ToggleOption('number')<CR>
nnoremap <silent>[Option]w :<C-u>call <SID>ToggleOption('wrap')<CR>
nnoremap <silent>[Option]/ :<C-u>call <SID>ToggleOption('wrapscan')<CR>
function! s:ToggleOption(option)
if has_key(g:toggle_option_extra, a:option)
for e in g:toggle_option_extra[a:option]
if exists('+' . e) && eval("&" . e) == 0
execute 'setlocal' e . '!' e . '?'
return
endif
endfor
elseif exists('+' . a:option)
execute 'setlocal' a:option . '!' a:option . '?'
endif
endfunction
let g:toggle_option_extra = {
\ 'number' : ['number', 'relativenumber']
\ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment