Consider the following script:
vim9script var buffer_info = getbufinfo() g:buflist =  for dd in getbufinfo() add(g:buflist, dd['bufnr']) endfor def g:BufListRemove() # If the buffer is in the buffer list, then remove it. var idx = index(g:buflist, bufnr()) if idx != -1 remove(g:buflist, idx) endif enddef augroup myaugroup autocmd BufDelete,BufWipeout * g:BufListRemove() augroup END
Say that I have 4 buffers opened, numbered from
echo g:buflist (after having run the above script) returns
[1, 2, 3, 4], which is fine.
Say now that the current buffer is
4 and I run
echo g:buflist correctly returns
[1, 2, 3].
The problem arise when the wiped out (or deleted) buffer is not
Foe example, If the current buffer is
3 and I run
echo g:buflist returns
Inspection of the documentation of
BufWipeout (same for
BufDelete) say that
NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer being deleted "<afile>". Don't change to another buffer, it will cause problems.
But then I have no idea on how to circumnavigate this note.
What I want is that if I run e.g.
:bw1 , then the item 1 is removed from
g:buflist and not the current buffer.
How to achieve that?