tags:

views:

95

answers:

2

I had thought vim was all powerful until I wanted to get rid of buffers in the list and reuse them for something else. For example, if I have

1 "f1.h"
2 "f2.h"
3 "f3.h"
4 "f1.cpp"
5 "f2.cpp"
6 "f3.cpp"

and I want to replace f1.h - f3.h with something else, but in the same buffer sequence:

1 "n1.h"
2 "n2.h"
3 "n3.h"
4 "f1.cpp"
5 "f2.cpp"
6 "f3.cpp"

I can't figure out how to do it. I can do "1,3bd" and delete buffers 1-3, or even "1,3bw" and wipe them out, but don't see any way to reuse those numbers without restarting vim. The vim buffer faq at http://vim.wikia.com/wiki/Vim_buffer_FAQ appears to confirm this.

But I don't want to believe that vim really has this limitation, is there really no way to do this from within vim?

+1  A: 

I'd recommend using tabs instead (from vim 7). You can freely move them around with tabm and open new ones with tabe or tabnew. Plus, it's more obvious what is going on. You can also start vim with a bunch of tabs open using -p (IIRC).

Peter
Thanks for the suggestion, but one reason I prefer buffer numbers over tabs is that I often work with dozens or hundreds of files at a time. In a given session, I start to remember frequently used files by buffer number and quickly switch back and forth between them. That doesn't seem as easy to do with tabs.I suspect that is also why vim tries to maintain the persistence of buffer numbers, but if I have to reload a block of buffers (such as include files), I like to keep them at the top. That's the problem I'm trying to solve.
William Knight
+2  A: 

You cant reassign buffer numbers in the same session so my guess is your best bet is to look around at vimscript alternatives.

Theres buffer explorers like

http://www.vim.org/scripts/script.php?script_id=42 that handles sorting to most recent used files. Its also great for deleting buffers.

There are loads of other buffer switching scripts on vim.org that cater to their various authors needs. Or alternatively you could roll your own with some mappings.

I came up with this for django.

http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings

which gives me quick two/three keystroke access to 20 standard named files relative to an app directory. You could come up with something for your project on these lines.

My mappings are \1, \2, \3 etc so the number paradigm is still there

also \vr for ~/.vimrc \br for ~/.bashrc.

The important thing it can and should be a very efficient process.

michael
Your \1, \2, \3 mapping script points the way towards the answer I'm seeking and if I don't see anything better, I'll accept it. If this approach was extended systematically to create mappings for all the files in the buffer, in a desired sequence, then this would be an acceptable alternative to switching to any file by buffer number, especially if used in conjunction with a script that listed the files in the same mapped numeric sequence.
William Knight