You can use window variables to get this identifier:
" put unique window identifier into w:id variable
autocmd VimEnter,WinEnter * if !exists('w:id') | let w:id={expr_that_will_return_an_unique_identifier} | endif
: this should mean all windows. Or perhaps it’s better to check only those windows that you want to use immediately after creating the window. To find the window with id abc
, then switch to it:
function s:FindWinID(id)
for tabnr in range(1, tabpagenr('$'))
for winnr in range(1, tabpagewinnr(tabnr, '$'))
if gettabwinvar(tabnr, winnr, 'id') is a:id
return [tabnr, winnr]
endif
endfor
endfor
return [0, 0]
endfunction
<...>
let [tabnr, winnr]=s:FindWinID('abc')
execute "tabnext" tabnr
execute winnr."wincmd w"
In recent versions of Vim there is a function win_getid()
both win_id2tabwin()
instead of s:FindWinID
, and also win_gotoid()
, just to go to the window with the given identifier. Identifiers are supported by Vim itself, so even an opening window, for example, noautocmd wincmd s
cannot create a window without an identifier.
source
share