Skip to content

Commit

Permalink
Add [O, ]O and cO map groups to change all windows
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Feb 29, 2016
1 parent 11dc568 commit 3a33965
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugin/unimpaired.vim
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,29 @@ function! s:toggle(op) abort
return eval('&'.a:op) ? 'no'.a:op : a:op
endfunction

function! s:windo(command)
" By entering a window, its height is potentially increased from 0 to 1 (the
" minimum for the current window). To avoid any modification, save the
" window sizes and restore them after visiting all windows.
let winrestcmd = winrestcmd()
let currwin = winnr()
let prevwin = winnr('#') ? winnr('#') : 1
echom a:command
execute 'windo '.a:command
execute prevwin.'wincmd w'
execute currwin.'wincmd w'
silent! execute winrestcmd
endfunction

function! s:option_map(letter, option, mode) abort
exe 'nnoremap [o'.a:letter ':'.a:mode.' '.a:option.'<C-R>=<SID>statusbump()<CR><CR>'
exe 'nnoremap ]o'.a:letter ':'.a:mode.' no'.a:option.'<C-R>=<SID>statusbump()<CR><CR>'
exe 'nnoremap co'.a:letter ':'.a:mode.' <C-R>=<SID>toggle("'.a:option.'")<CR><CR>'

exe 'nnoremap [O'.a:letter.' :call <SID>windo('''.a:mode.' '.a:option.''')<CR><C-R>=<SID>statusbump()<CR><CR>'
exe 'nnoremap ]O'.a:letter.' :call <SID>windo('''.a:mode.' no'.a:option.''')<CR><C-R>=<SID>statusbump()<CR><CR>'
" XXX: uses the value of the current window to toggle all.
exe 'nnoremap cO'.a:letter.' :call <SID>windo('''.a:mode.' <C-R>=<SID>toggle("'.a:option.'")<CR>'')'
endfunction

nnoremap [ob :set background=light<CR>
Expand Down

0 comments on commit 3a33965

Please sign in to comment.