Rafid
Rafid

Reputation: 20189

Vim: Changing Buffer Numbers

I usually like to use buffer numbers to go to buffers quickly. Unfortunately, after many searches, opening some files, etc., the buffer numbers get crazy:

  1. Is there anyway to assign buffer numbers manually?
  2. Is there anyway to restart buffer numbering?

Upvotes: 17

Views: 7606

Answers (5)

Bruno Bronosky
Bruno Bronosky

Reputation: 70339

"the buffer numbers get crazy" Tell me about it! By the end of the day I'm easy over 100 buffers. But luckily, as you can see in this animation, you have tab completion for buffer names.

Hit :b se<Tab>

So, even though you can't renumber the buffers, you can still jump around easily.

It's also worth noting that it is doing *str* matching so I didn't have to search on "se" to go straight to that file. Typing :b uptab would have also taken me straight there. If there are more than one match, subsequent tabs will cycle over the matches (circularly). So, in this session I could cycle over my "test" files or my "py" files if I wished. This is BETTER than renumbering once you learn it!

Upvotes: 20

Chris Marks
Chris Marks

Reputation: 41

I think I figured out a way to do this. Use mksession: {session_filename}, close out your session, open {session_filename}, Look for the lines with badd {filename}, add/edit/delete/arrange these lines, then open it again with vim -S {session_filename}. The buffers will be in the new order. Be careful with deleting if it was a current or active file. I will be referenced in other places.

Upvotes: 4

BenJamin
BenJamin

Reputation: 783

You could try this buffer-enancment plugin.

It is a small layer over native buffer switching that lets you assign buffers numbers and recall them by that number like such:

assign current buffer to the number 1

1<leader><C-6>

when you want to load that buffer switch to it like you would normally switch to buffer 1

1<C-6>

It works by saving a dictionary of the buffers you assign loading them instead of the regular buffer if one is present. If the key is not present it will simply try to load the buffer with that number.

Upvotes: 1

Mironor
Mironor

Reputation: 1187

Try bufferexplorer plugin for vim. It's also usefull to map some keys to Fx keys,here's an example:

"Bufexplorer mapings
nmap <F5> <Esc>:BufExplorer<cr>
vmap <F5> <esc>:BufExplorer<cr>
imap <F5> <esc>:BufExplorer<cr>

" F6 - previous buffer
nmap <F6> :bp<cr>
vmap <F6> <esc>:bp<cr>i
imap <F6> <esc>:bp<cr>i

" F7 - next buffer
nmap <F7> :bn<cr>
vmap <F7> <esc>:bn<cr>i
imap <F7> <esc>:bn<cr>i

Upvotes: 2

moinudin
moinudin

Reputation: 138357

It is not possible to assign buffer numbers manually, or reassign them for that matter. The only way to restart buffer numbering is to restart vim. You might be interested in the SelectBuf script.

Upvotes: 10

Related Questions