2

I have vim buffers like this:

1 "file1.txt"
2 "file2.txt"
3 "file3.txt"

and I want re-assign buffer numbers like this:

1 "file2.txt"
2 "file1.txt"
3 "file3.txt"

How do I do this?

2 Answers 2

4

From :help :ls:

Each buffer has a unique number. That number will not change, so you can always go to a specific buffer with ":buffer N" or "N CTRL-^", where N is the buffer number.

Why do you need to reassign those numbers? Maybe there is another thing to do to help you in your task?

Sign up to request clarification or add additional context in comments.

5 Comments

I don't use windows and i don't use tabs in vim. I use buffers for manipulating files which I am editing. Maybe there ares some other ways to do this in vim?
Maybe you could harvest from the BufExplorer plug-in, or from :args and :argdo commands, from windowing and tabbing. All of them.
I am new with vim. And I do not use plug-ins yet. I want to learn standard vim commands and functions.
If you are new you should take time to learn, it won't be done in a single day! You can find vim geeks on IRC Freenode server (#vim channel) who will be happy to help you for any problem you might have.
You can use tab-completion in command mode, like :b <tab>. Wildmenu also improves greatly the completion (:set wildmode). With :b, tab-completion also works with substrings. With your example, :b 1<tab> will complete to file1.txt.
0

While it is true that you can't technically re-assign buffer numbers there is this plugin that allows you to act like you can:

https://github.com/gelus/vim-buffer-enhancement

it allows you to map buffers to numbers by hitting <count><leader><C-6>

Then returning to the mapped buffers in the same way you switch to a regular buffer <count><C-6>

so for your example:

  • pull up file2.txt and hit 1<leader><C-6>
  • pull up file1.txt and hit 2<leader><C-6>
  • file3 is already at buffer 3, ( you can map it if you want, but it would work the same )

  • now hitting 1<C-6> will take you to file2.txt, 2<C-6> will take you to file1.txt and 3<C-6> will still take you to file3.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.