From aaec671ad5a3125c136d538fca2d75406e951177 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 10 Jun 2014 13:23:21 +0200 Subject: [PATCH] Add `[O`, `]O` and `cO` map groups to change all windows The `s:windo` wrapper is based on https://github.com/vim-scripts/ArgsAndMore/blob/848dec40e4d23fa3124c83009512eb5a22bd36b8/autoload/ArgsAndMore.vim#L127-L138. --- plugin/unimpaired.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugin/unimpaired.vim b/plugin/unimpaired.vim index 4894713..828c3a4 100644 --- a/plugin/unimpaired.vim +++ b/plugin/unimpaired.vim @@ -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.'' exe 'nnoremap ]o'.a:letter.' :set no'.a:option.'' exe 'nnoremap co'.a:letter.' :set =toggle("'.a:option.'")' + + exe 'nnoremap [O'.a:letter.' :call windo(''set '.a:option.''')' + exe 'nnoremap ]O'.a:letter.' :call windo(''set no'.a:option.''')' + exe 'nnoremap cO'.a:letter.' :call windo(''set =toggle("'.a:option.'")'')' endfunction nnoremap [ob :set background=light