0

As title. Is it possible to change the current buffer by vimscript to the (only) [No Name] buffer?

I need these tools:

  • an API to return all (loaded) buffers
  • loop through each of them
    • if the buffer is a No Name-buffer, then record its buffer number
  • an API to edit that buffer on the current window (split) by that buffer number.

I put emphasis on "the only" is that what I want to do is to keep only one No Name-buffer, so there won't be many No Name-buffers that spam out there. To do so my idea is that whenever I want to open a new No Name-buffer use a script to check if there is one: if so switch to it, if not then really create one.

2
  • Use vim however you want, but to me this would be odd. When I run :new or :enew, I want a new buffer (not to automatically re-use an existing one). A :Scratch command that re-uses the same buffer might be interesting, though.
    – D. Ben Knoble
    Jan 10 at 15:49
  • @D.BenKnoble: Just to provide context: I just created a plugin (while in Lua). In the implementation I need to use :enew to substitute the current buffer to a No Name, while I don't want to be spammed by many No Name buffers.
    – job_start
    Jan 10 at 18:03
2

an API to return all (loaded) buffers

:h getbufinfo()

loop through each of them

:h filter()

if the buffer is a No Name-buffer

:echo empty(bufname(N))
:echo empty(getbufinfo(N)[0].name)

an API to edit that buffer on the current window (split) by that buffer number

:h :buffer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.