Suppose I have a file C:/Users/Pedro/Desktop/foo.txt
. If I open Gvim and run :echo bufnr('C:/Users/Pedro/Desktop/foo.txt')
it returns -1
since the buffer is not loaded. I know I can edit the file (i.e run execute "edit " 'C:/Users/Pedro/Desktop/foo.txt'
) and then I will obtain a buffer number with bufnr()
. However, by editing the file, it will also become visible. So my question is: how can I get (or assign) a buffer number to a buffer that is not currently loaded in Vim without making it visible?
Equivalently: is there a way to load a vim buffer without making it visible?
Edit: I know about :hide
but the problem with it is that it will not work on the last window on screen.