3

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.

petobens
  • 1,330
  • 1
  • 12
  • 23
  • Is this specifically when no other buffers are already open? If other buffers are open do you want to just continue displaying the last buffer? – Randy Morris Aug 19 '15 at 15:40
  • Hi @RandyMorris. There might be other buffers open (or not). I just want to get a buffer number without altering the current window/buffer display. – petobens Aug 19 '15 at 15:42

1 Answers1

4

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.

romainl
  • 186,200
  • 21
  • 280
  • 313