Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: get buffer number for unloaded buffer

Tags:

vim

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.

like image 955
petobens Avatar asked Apr 15 '26 22:04

petobens


1 Answers

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.

like image 178
romainl Avatar answered Apr 17 '26 16:04

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!