How to stop buffer number incrementing when writing to a temp file?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to stop buffer number incrementing when writing to a temp file?

Andrew Stewart
Hello!

I started this thread on vim_dev[1] and it was suggested I continue here instead.

> I fail to understand, why this is a problem, but you should be able to work around that using the writefile() function, which seems to be better suited for such a case.

Over the course of a day that VimL runs hundreds or thousands of times, and when I only work on a dozen files it seems...inefficient that the buffer number is up in the hundreds or higher.  It doesn't break anything but it's an unwanted side-effect.

I looked at writefile() and confess I was confused by its documentation.  How does one call it so that the buffer's contents are written exactly as-is, i.e. without changing line endings or adding/removing a final line ending?

Many thanks,

Andy

[1] https://groups.google.com/forum/#!topic/vim_dev/oDyCq5Al7FY

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to stop buffer number incrementing when writing to a temp file?

stillLearningVim
Hi Andy,

I'm not a vim expert, but it looks like we don't have a way to keep the buffer number from increasing. I haven't used vim's scratch buffer before, but maybe you can use that for editing a temp file.

From: http://vim.wikia.com/wiki/Vim_buffer_FAQ

Is it possible to configure Vim, by setting some option, to re-use the number of a deleted buffer for a new buffer?

No. Vim will not re-use the buffer number of a deleted buffer for a new buffer. Vim will always assign the next sequential number for a new buffer. The buffer number assignment is implemented this way, so that you can always jump to a buffer using the same buffer number. One method to achieve buffer number reordering is to restart Vim. If you restart Vim, it will re-assign numbers sequentially to all the buffers in the buffer list (assuming you have properly set 'viminfo' to save and restore the buffer list across Vim sessions).



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to stop buffer number incrementing when writing to a temp file?

Justin M. Keyes
In reply to this post by Andrew Stewart
On Wed, Apr 1, 2015 at 10:23 AM,  <[hidden email]> wrote:
> Hello!
>
> I started this thread on vim_dev[1] and it was suggested I continue here instead.
>
>> I fail to understand, why this is a problem, but you should be able to work around that using the writefile() function, which seems to be better suited for such a case.
>
> Over the course of a day that VimL runs hundreds or thousands of times, and when I only work on a dozen files it seems...inefficient that the buffer number is up in the hundreds or higher.  It doesn't break anything but it's an unwanted side-effect.

Isn't your use case mentioned in vim_dev, a perfect application of
tabs? Tabs have very predictable and stable numbering. It could be
argued that tabs exist in part to serve the use case you mention.

Buffers, in contrast, are the fundamental userland "data structure" in
Vim (and Emacs), so it is important that identity for a given buffer
is unique for the entire session.

For example, in the fugitive.vim plugin, the Glog command fills the
quicklist with buffer entries, and this will quickly increment your
buffer number to the hundreds or thousands. Instead of fighting this,
I say embrace it.

P.S. In the future I hope to see buffers made even more flexible and
useful in Vim, like Emacs...

Justin M. Keyes

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.