@@ -68,33 +68,41 @@ function! s:LeaveWin()
6868 endif
6969endfunction
7070
71- " Like windo but restore the current buffer.
72- " See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position
73- function ! s: WinDo ( command )
74- " avoid errors in CmdWin
75- if exists (' *getcmdwintype' ) && ! empty (getcmdwintype ())
76- return
77- endif
78- " Work around Vim bug.
79- " See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg
80- let curaltwin = winnr (' #' ) ? winnr (' #' ) : 1
81- let currwin= winnr ()
82- if &scrollopt = ~# ' \<jump\>'
83- set scrollopt -= jump
84- let l: restore = ' set scrollopt+=jump'
85- endif
86- " Work around Vim bug.
87- " See https://github.com/vim/vim/issues/4622#issuecomment-508985573
88- let l: currwinwidth = &winwidth
89- let &winwidth = &winminwidth > 0 ? &winminwidth : 1
90- silent ! execute ' keepjumps noautocmd windo ' . a: command
91- silent ! execute ' noautocmd ' . curaltwin . ' wincmd w'
92- silent ! execute ' noautocmd ' . currwin . ' wincmd w'
93- if exists (' l:restore' )
94- exe l: restore
95- endif
96- let &winwidth = l: currwinwidth
97- endfunction
71+ " Like :windo, but restores the current window and avoids side effects.
72+ if exists (' *win_execute' )
73+ function ! s: WinDo ( command )
74+ for w in range (1 , winnr (' $' ))
75+ call win_execute (win_getid (w ), a: command , 1 )
76+ endfor
77+ endfunction
78+ else
79+ " See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position
80+ function ! s: WinDo ( command )
81+ " avoid errors in CmdWin
82+ if exists (' *getcmdwintype' ) && ! empty (getcmdwintype ())
83+ return
84+ endif
85+ " Work around Vim bug.
86+ " See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg
87+ let curaltwin = winnr (' #' ) ? winnr (' #' ) : 1
88+ let currwin= winnr ()
89+ if &scrollopt = ~# ' \<jump\>'
90+ set scrollopt -= jump
91+ let l: restore = ' set scrollopt+=jump'
92+ endif
93+ " Work around Vim bug.
94+ " See https://github.com/vim/vim/issues/4622#issuecomment-508985573
95+ let l: currwinwidth = &winwidth
96+ let &winwidth = &winminwidth > 0 ? &winminwidth : 1
97+ silent ! execute ' keepjumps noautocmd windo ' . a: command
98+ silent ! execute ' noautocmd ' . curaltwin . ' wincmd w'
99+ silent ! execute ' noautocmd ' . currwin . ' wincmd w'
100+ if exists (' l:restore' )
101+ exe l: restore
102+ endif
103+ let &winwidth = l: currwinwidth
104+ endfunction
105+ endif
98106
99107" WinEnter then TabEnter then BufEnter then BufWinEnter
100108function ! s: UpdateWin ()
0 commit comments