When one types args
command in vim, one is shown a list of currently edited files (buffers). However, if the list of files is long (for example, more than 20), it is very hard to tell what buffer number a given file name corresponds to without manually counting them. The goal is to be able to check quickly buffer number a given file corresponds to and jump to it using the b
(+bufferNumber) command.
Is there a way to append or prepend the shown (using args
command) file names with their buffer numbers?
Some examples of expected output:
1 fileName1
2 fileName2
or
fileName1 1
fileName2 2
Thank you very much for your help!
TL;DR: you want to navigate buffers so you should use a command that lists buffers, not a command that lists arguments.
one is shown a list of currently edited files (buffers).
No. One is shown a list of arguments, that may or may not have corresponding buffers.
it is very hard to tell what buffer number a given file name corresponds to without manually counting them.
The position of an argument in the argument list is not guaranteed to match with its corresponding buffer's position in the buffer list, if it even has one.
The goal is to be able to check quickly buffer number a given file corresponds to and jump to it using the
b
(+bufferNumber) command.
There already is a command for that: :help :buffers
.
Basically, there is no guaranteed relationship between a "file", an "argument", and a "buffer" so one should use commands adapted to the object one is trying to manipulate. Listing arguments in order to navigate buffers is utterly pointless.
You are confusing and conflating a bunch of notions, here: "files", "arguments", and "buffers". To be honest, Vim's own command names and documentation can be confusing so here is a high-level explanation.
"Files" are the files on your disk. You may think in "files" terms when you do something at that level of granularity ("I want to edit the README.md
of this project." or "I want to write the content of this buffer to file foo.rb
") but, outside of that use case, there are more appropriate mental models.
If you think in "files", use commands that deal with filesystem I/O, like :help :w
, :help :r
, etc.
Conceptually, "arguments" are the filenames provided to Vim at startup:
$ vim foo.rb bar.spec.rb
But, of course, it became possible to change the argument list at runtime so it sort of lost its original meaning and it is probably more useful to think of "arguments" as "filenames": you have a list of filenames whose initial value is the filenames passed as argument to Vim upon startup, to which you can add entries and from which you can remove entries.
If you want to manipulate arguments, use argument-oriented commands like :help :argdo
, :help :next
, etc.
NOTE: the documentation uses the word "file" a lot in the context of the argument list where it should use the more appropriate "argument".
"Buffers" are exactly what you would call "document" in other more familiar programs. They can be associated to a "file" or an "argument" or not.
If you want to manipulate buffers, use buffer-oriented commands like :help :buffers
, :help :bufdo
, etc.
NOTE: if you check the documentation for :buffers
you will see that it has two synonyms, :files
and :ls
, which makes things pretty confusing. The list you get may map to actual "files" on your disk or not so the distinction between "files", "arguments", and "buffers" is important.