0

How can I create a new buffer just after(next to) the one I am on ?

Let say I have three buffers opened (1, 2, 3) and I am (my cursor) currently in buffer 1. If I add a new buffer (with :edit for example) it will open it in buffer 4, but instead I want to open it in buffer 2 without deleting other existent buffers (so maybe buffer 2 and 3 will become 3 and 4, it's a sort of insert).

Are there any way to do this? (I did some research and found nothing). Thanks.

  • Why do you want to change a buffer number in the first place? – statox Jan 4 '18 at 16:00
  • To switch more easily between buffers with :bn and :bp – akio Jan 4 '18 at 16:36
  • 3
    I think that you are looking for the wrong solution: you would probably be more efficient if you learn other commands than bn and bp for example this SO answer might contain some interesting stuff for you. – statox Jan 4 '18 at 16:45
1

There is no way to target buffer numbers in order to rearrange them or to say, "now it contains this file".

You could do a :b 2 + :%d_ + :read somefile, but that won't be enough, you'd also need to clear filetype, filename, local options and variables, syntax highlighting, and so on.

The best thing to do: forget buffer numbers, there is no way to organize them as you'd like.

0

If you're concerned to keep things "in order", using :argedit or :argadd adds the filename to the list and you can then stick to :n :N for navigation. I usually map a pair of keys (e.g. F3/F4) to mean previous / next so I don't have to keep hitting ESCAPE and : when I'm editing:

map! <special> <F3> <C-\><C-o><F3>
map! <special> <F4> <C-\><C-o><F4>
map <special> <F3> :N<Enter>
map <special> <F4> :n<Enter>

Yes, I know how lazy that is ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.