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 Jun 2, 2015
1 parent 3548479 commit aaec671
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 @@ -202,10 +202,29 @@ function! s:toggle(op)
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

execute 'windo ' . a:command

execute prevwin . 'wincmd w'
execute currwin . 'wincmd w'
silent! execute winrestcmd
endfunction

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

exe 'nnoremap [O'.a:letter.' :call <SID>windo(''set '.a:option.''')<CR>'
exe 'nnoremap ]O'.a:letter.' :call <SID>windo(''set no'.a:option.''')<CR>'
exe 'nnoremap cO'.a:letter.' :call <SID>windo(''set <C-R>=<SID>toggle("'.a:option.'")<CR>'')<CR>'
endfunction

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

0 comments on commit aaec671

Please sign in to comment.