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.
You can use :badd somefile to add somefile to the buffer list without leaving the current buffer.
:argadd does the same for the argument list.
See :help :badd and :help :argadd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With