|
Hi,
If i have a large number of buffers that i've opened over time in a Vim session. Is there an easy way to renumber them so that they are numbered in alphabetical path order? e.g. if :buffers was: 1 h "base/three.c" 3 h "base/one.c" 5 h "plugin/two.c" 7 h "alpha/test.c" I'd like to type command and get :buffers 1 h "alpha/test.c" 2 h "base/one.c" 3 h "base/three.c" 4 h "plugin/two.c" Cheers for any help, Dom |
|
From :help buffer
Each buffer has a unique number. That number will not change, so you can always go to a specific buffer with ":buffer N" or Thus, What you are asking for is not possible without opening the files in the order you want the numbers to be assigned. -Rajesh -----Original Message----- From: Dominic Evans [mailto:[hidden email]] Sent: Thursday, September 15, 2005 5:33 PM To: vim mailing list Subject: Buffer Sorting Hi, If i have a large number of buffers that i've opened over time in a Vim session. Is there an easy way to renumber them so that they are numbered in alphabetical path order? e.g. if :buffers was: 1 h "base/three.c" 3 h "base/one.c" 5 h "plugin/two.c" 7 h "alpha/test.c" I'd like to type command and get :buffers 1 h "alpha/test.c" 2 h "base/one.c" 3 h "base/three.c" 4 h "plugin/two.c" Cheers for any help, Dom |
|
Yes but,
assumedly one could store the list of files in a variable, unload all the buffers, and then open all the files in the required order? Thats the sort of thing I was expecting really. Cheers, Dom On 15/09/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote: > From :help buffer > > Each buffer has a unique number. That number will not change, > so you can always go to a specific buffer with ":buffer N" or > > Thus, What you are asking for is not possible without opening the files in > the order you want the numbers to be assigned. > > -Rajesh > > -----Original Message----- > From: Dominic Evans [mailto:[hidden email]] > Sent: Thursday, September 15, 2005 5:33 PM > To: vim mailing list > Subject: Buffer Sorting > > > Hi, > > If i have a large number of buffers that i've opened over time in a > Vim session. Is there an easy way to renumber them so that they are > numbered in alphabetical path order? > > e.g. > > if :buffers was: > > 1 h "base/three.c" > 3 h "base/one.c" > 5 h "plugin/two.c" > 7 h "alpha/test.c" > > I'd like to type command and get > :buffers > > 1 h "alpha/test.c" > 2 h "base/one.c" > 3 h "base/three.c" > 4 h "plugin/two.c" > > Cheers for any help, > Dom > |
|
In reply to this post by Dominic Evans
Does this list the buffers in alphabetical order in its window then?
On 15/09/05, R. shankar <[hidden email]> wrote: > Dominic, > > I think you are looking at a way to go to buffer quickly and feels that, > if the buffers are arranged alphabetically it would be helpful. > You could use the Buffer Explorer plugin to do this. > Using simple commands like \be opens the explorer. You could the > buffer either in the alphabetical way or in the asc/des order of the buffer > numbers. > Pressing the Enter on a buffer name would take to that buffer. > > Hope this is what you are looking for. > > > Regards, > shankar > > > Hi, > > If i have a large number of buffers that i've opened over time in a > Vim session. Is there an easy way to renumber them so that they are > numbered in alphabetical path order? > > e.g. > > if :buffers was: > > 1 h "base/three.c" > 3 h "base/one.c" > 5 h "plugin/two.c" > 7 h "alpha/test.c" > > I'd like to type command and get > :buffers > > 1 h "alpha/test.c" > 2 h "base/one.c" > 3 h "base/three.c" > 4 h "plugin/two.c" > > Cheers for any help, > Dom > > > > > > > > > > > > -- > R.SHANKAR , SMTS, TRANSWITCH > C/o, R.S.Rana, > Flat No 2, First Floor, House No. 212A/1 > Baba Ganga Nath Market, Near community Hall, > Munirka Village New Delhi . PIN : 110067 > PH(OFFICE): +(91)(11)26165111, Mobile: 9899125114 > PH(RES): (91)(11)26161875 > Email: [hidden email], [hidden email] > > > > > > > |
|
In reply to this post by Dominic Evans
On Thu, Sep 15, 2005 at 01:02:42PM +0100, Dominic Evans wrote:
> Hi, > > If i have a large number of buffers that i've opened over time in a > Vim session. Is there an easy way to renumber them so that they are > numbered in alphabetical path order? As other people have already mentioned, this isn't possible without loading the files in the given order. You may be interested in the bufexplorer plugin <http://www.vim.org/scripts/script.php?script_id=42> which provides a list of the buffers you have open. The plugin allows you to sort this list by: - Most Recently Used - Fullpath - Buffer number - Filename HTH, James -- GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]> |
|
In reply to this post by Dominic Evans
Not possible to change the numbers of the buffers, but possible to see them sorted alphabetically: see http://www.vim.org/tips/tip.php?tip_id=976 (The latest version is toward the bottom.) --Suresh -----Original Message----- From: Dominic Evans [mailto:[hidden email]] Sent: Thursday, September 15, 2005 5:03 AM To: vim mailing list Subject: Buffer Sorting Hi, If i have a large number of buffers that i've opened over time in a Vim session. Is there an easy way to renumber them so that they are numbered in alphabetical path order? e.g. if :buffers was: 1 h "base/three.c" 3 h "base/one.c" 5 h "plugin/two.c" 7 h "alpha/test.c" I'd like to type command and get :buffers 1 h "alpha/test.c" 2 h "base/one.c" 3 h "base/three.c" 4 h "plugin/two.c" Cheers for any help, Dom |
|
In reply to this post by Dominic Evans
> assumedly one could store the list of files in a variable,
> unload all the buffers, and then open all the files in the > required order? Thats the sort of thing I was expecting > really. Something like the following could be crammed into a mapping or function if so desired: let tn=tempname() exec "redir > ".tn ls! redir END exec "sp ".tn v/./d %s/.*"\(.*\)".*/\1 %!sort exec "1,".line("$")." bwipe!" %s/ /\\ /g %j s/^/argadd / w so % bwipe call delete(tn) unlet tn It doesn't quite have the behavior you want, as vim doesn't seem to reuse wiped buffers. So with the original listing coming back something like "d c b a" for your file names as #1, #2, #3, and #4, running this script will remove them, and then give you "a b c d" as buffers #6, #7, #8, and #9. This may have difficulty with non-named buffers, as you're likely to hose them. Make sure you've written all the files before you do this. Oh, and another caveat, if you've got any windows open on any of these files, the windows will be closed. It's ugly, it's hackish, and it's got some pretty nasty side effects. But if you can swallow it, it does renumber your buffers in increasing order alphabetically :) -tim |
|
In reply to this post by Dominic Evans
On Thu, 15 Sep 2005 at 1:25pm, Dominic Evans wrote: > Yes but, > > assumedly one could store the list of files in a variable, unload all > the buffers, and then open all the files in the required order? Thats > the sort of thing I was expecting really. > > Cheers, > Dom This should be possible, but what I think you want is an easier lookup rather than really renumbering buffers. As suggested by others, if you are not already using a buffer explorer that supports sorting by name, you should look at vim.org for at least a couple that can support this. One of them called bufexplorer is already suggested. Since you seem to use one Vim session over a few days accumulating a large set of files, just like me, you might appreciate my buffer explorer called SelectBuf, which supports both name and MRU sorting as well as others, and is designed especially to work with long sessions in Vim. It works much faster than other list based buffer explorers because it updates the list incrementally. The performance essentially doesn't degrade much as the list grows, at least for most operations. Please give it a try. http://www.vim.org/script.php?script_id=107 -- HTH, Hari > > On 15/09/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote: > > From :help buffer > > > > Each buffer has a unique number. That number will not change, > > so you can always go to a specific buffer with ":buffer N" or > > > > Thus, What you are asking for is not possible without opening the files in > > the order you want the numbers to be assigned. > > > > -Rajesh > > > > -----Original Message----- > > From: Dominic Evans [mailto:[hidden email]] > > Sent: Thursday, September 15, 2005 5:33 PM > > To: vim mailing list > > Subject: Buffer Sorting > > > > > > Hi, > > > > If i have a large number of buffers that i've opened over time in a > > Vim session. Is there an easy way to renumber them so that they are > > numbered in alphabetical path order? > > > > e.g. > > > > if :buffers was: > > > > 1 h "base/three.c" > > 3 h "base/one.c" > > 5 h "plugin/two.c" > > 7 h "alpha/test.c" > > > > I'd like to type command and get > > :buffers > > > > 1 h "alpha/test.c" > > 2 h "base/one.c" > > 3 h "base/three.c" > > 4 h "plugin/two.c" > > > > Cheers for any help, > > Dom > > > > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com |
|
In reply to this post by Tim Chase-2
> -----Original Message----- > From: Tim Chase [mailto:[hidden email]] > Sent: Thursday, September 15, 2005 6:10 AM > To: [hidden email] > Cc: Goli, Rajesh (Rajesh); vim mailing list > Subject: Re: Buffer Sorting > > > assumedly one could store the list of files in a variable, > > unload all the buffers, and then open all the files in the > > required order? Thats the sort of thing I was expecting > > really. > > Something like the following could be crammed into a mapping or > function if so desired: > > let tn=tempname() > exec "redir > ".tn > ls! > redir END > exec "sp ".tn > v/./d > %s/.*"\(.*\)".*/\1 > %!sort > exec "1,".line("$")." bwipe!" > %s/ /\\ /g > %j > s/^/argadd / > w > so % > bwipe > call delete(tn) > unlet tn I was about to answer with something similar, but using a no_file buffer instead of tempname(). I like yours better if it means you could recover your filelist in event of a crash. :) > It doesn't quite have the behavior you want, as vim doesn't seem > to reuse wiped buffers. So with the original listing coming back > something like "d c b a" for your file names as #1, #2, #3, and > #4, running this script will remove them, and then give you "a b > c d" as buffers #6, #7, #8, and #9. True, but after closing vim and reentering, they will be numbered from 1; the reordering is the important part. This is one thing that bufexplorer and SelectBuf won't do. It might be nice if there were options for :wv to convert all bufnames to full paths and to output the buffer list (and everything associated with it) in sorted order ... a lot of work, maybe. > This may have difficulty with non-named buffers, as you're likely > to hose them. Make sure you've written all the files before you > do this. You could eliminate the non-named buffers by adding g/\[No File]/d after the v/./d and a :wall at the top would only make sense. The non-named buffers would float to the top, but they wouldn't be lost. > Oh, and another caveat, if you've got any windows open on any of > these files, the windows will be closed. Adding a loop at the top to save the window states, and one at the bottom to retore them, will fix that. I've probably got some code around somewhere that does just that, but am too lazy to look for it. :) Let's see ... probably use :windo and :mkview, generate a view name using winnr(), :let g:nbr_windows=winnr() so that highest winnr() is saved. Then do a :while loop using :loadview to recreate windows 1 thru g:nbr_windows. -Keith > It's ugly, it's hackish, and it's got some pretty nasty side > effects. But if you can swallow it, it does renumber your > buffers in increasing order alphabetically :) > > -tim |
|
> instead of tempname(). I like yours better if it means you
> could recover your filelist in event of a crash. :) a 100% unintended side effect :) >> It's ugly, it's hackish, and it's got some pretty nasty side >> effects. But if you can swallow it, it does renumber your >> buffers in increasing order alphabetically :) I tried to find as many cautions as I could about the nasty things that could go wrong, but I'm sure there were other edge cases that I missed. However, most of them, as you suggested, should be workaroundable (is that a word? :) Hopefully my suggestion offered a basis from which to build a solution that does what the OP wanted, mix in a few of Keith's suggestions, and bake at 350 for 20-25 minutes :) -tim |
| Powered by Nabble | See how NAML generates this page |
