Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Changing Buffer Numbers

Tags:

vim

buffer

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?

Thanks.

like image 662
Rafid Avatar asked Dec 28 '10 10:12

Rafid


4 Answers

"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!

like image 99
Bruno Bronosky Avatar answered Nov 16 '22 18:11

Bruno Bronosky


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.

like image 33
moinudin Avatar answered Nov 16 '22 16:11

moinudin


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
like image 2
Mironor Avatar answered Nov 16 '22 16:11

Mironor


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.

like image 3
Chris Marks Avatar answered Nov 16 '22 18:11

Chris Marks