From 07c651e47c735c61849487b7c1177bc65d9518e4 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 `=O` 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugin/unimpaired.vim b/plugin/unimpaired.vim index 1a32d34..4032804 100644 --- a/plugin/unimpaired.vim +++ b/plugin/unimpaired.vim @@ -241,14 +241,28 @@ function! s:toggle(op) abort return eval('&'.a:op) ? 'no'.a:op : a:op endfunction -function! s:cursor_options() abort - return &cursorline && &cursorcolumn ? 'nocursorline nocursorcolumn' : 'cursorline cursorcolumn' +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, mode) abort call s:map('n', '[o'.a:letter, ':'.a:mode.' '.a:option.'=statusbump()') call s:map('n', ']o'.a:letter, ':'.a:mode.' no'.a:option.'=statusbump()') call s:map('n', '=o'.a:letter, ':'.a:mode.' =toggle("'.a:option.'")') + + exe s:map('n', '[O'.a:letter, ':call windo('''.a:mode.' '.a:option.''')=statusbump()') + exe s:map('n', ']O'.a:letter, ':call windo('''.a:mode.' no'.a:option.''')=statusbump()') + " NOTE: uses the value of the current window to toggle all. + exe s:map('n', '=O'.a:letter, ':call windo('''.a:mode.' =toggle("'.a:option.'")'')') endfunction call s:map('n', '[ob', ':set background=light')