0

Consider the following snippet:

vim9script
# Set stuff in the newly created window
var my_win_nr = winnr('$')
var my_win_id = win_getid(my_win_nr)
win_execute(my_win_id, 'wincmd L')
win_execute(my_win_id, 'vertical resize 50')
win_execute(my_win_id, 'file MyStuff')
win_execute(my_win_id,
    \    'setlocal buftype=nofile bufhidden=hide
    \ nobuflisted noswapfile nowrap
    \ nonumber equalalways winfixwidth')
exe ":close"

By that I have a) a winid for a window that I set with some properties set and b) a buffer called MyStuff with some properties set.

How to re-open the same window on the same buffer with all the properties that I set so far in Vim9script by using functions or methods?

EDIT: From the docs you won't understand it. It is claimed that the ID is unique for a window, but when you create a new window you get a new ID. This suggest that the old ID data still live somewhere even if the window is not displayed on screen (and therefore one may think that such data may be eventually retrieved).

2
  • You closed the window. You don't re-open it, It's gone.
    – romainl
    Apr 16 at 20:41
  • "This suggest that the old ID data still live somewhere even if the window is not displayed on screen (and therefore one may think that such data may be eventually retrieved)." No. Not at all.
    – romainl
    Apr 17 at 7:09

2 Answers 2

0

A window has both a number and an id.

The window number is relative to the other window numbers of tab page within which the window exists: the topmost/leftmost window has number 1, etc. If you close window number n and there is a window number n+1, then that window becomes number n. It is also possible to move a window so that its number and that of other windows change over time. You can close the last window, for example, and then create a new last window which will have the same number as the one you just closed.

The window id is like the buffer id. It is absolute and never changes over time. New windows get an incremental id and closed windows disappear for good. Nothing is remembered of it.

You can close the window with number 4 and id 1234 and then create a new window at the same physical location. The new window will have the same number 4 but it will have id 1235 (or some other number if other windows where created in the mean time). It is a different window with different attributes and there is nothing in the doc that indicates otherwise.

1
  • ... nor that indicates that :p
    – Barzi2001
    Apr 17 at 8:06
0

I suggest vim-obsession. Sessions are restored automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.