1

I've been learning vi (as an autodidact) for some weeks. Actually I'm not yet sure about if I'm using vi or vim (does the command vi open vim if vim is installed?).

Now I'm trying to edite multiple files (more than two, in general). To do so I found useful the commands :ar, :argadd, :argd and so on. Then I read that another way is to use buffers, i.e. commands like :ls, :b, :sb and so on.

At the moment I don't understand the difference very well (I searched on the web and found something; maybe everything is clear but.. maybe I'm too new to vi to understand what I found).

What I noticed is that if I navigate from a file to another using :n, then the square brackets I see when entering :ar have been transferred from the preceding to the following file. If I use :b n (n is the index of a buffer) the %a and # labels in the list :ls correctly change, whereas if I enter :ar, the brackets are still those before the :b command. To summarize, I noticed that when I navigate arguments, both :ls and :ar's outputs change; when I navigate buffers, only :ls's output changes, that of :ar remaining fixed.

Can anyone help me to understand practical differences between arguments and buffers?

  • Which are the pros and cons of navigate files in the former or latter method?
  • Is it possible (and convenient/easy?) to use both the methods?
  • And other question I'm not even capable of formulate now (i.e. other information are welcomed).
3

The only system I know of that comes with the real vi by default is Arch Linux. In all the others, the vi command is some kind of "alias" that points to a more advanced vi clone like nvi or vim. So chances are that you are actually using Vim.

Indeed, arguments and buffers have a special relationship.

Adding elements to the argument list also adds them to the buffer list but…

  • removing arguments from the argument list won't remove their counterpart in the buffer list and vice-versa,
  • changing the order of the argument list has no impact on the order of the buffer list (which can't be changed).

On the navigation side, moving to another argument also changes the current buffer but moving to another buffer doesn't change the current argument.

Which are the pros and cons of navigate files in the former or latter method?

argument list pros

  • easy to manipulate → flexible

argument list cons

  • easy to manipulate → unreliable

buffer list pros

  • hard to manipulate → reliable

buffer list cons

  • hard to manipulate → inflexible

Is it possible (and convenient/easy?) to use both the methods?

Yes, but for different jobs.

The buffer list is a dependable representation of (parts of) the current state of your editor and you can safely rely on it for all things buffer-related.

As a transient structure, the argument list can't really be used as the backbone of a structured workflow.

My suggestion is to stick with buffers for any document-centric workflow and keep arguments for adding multiple buffers to the buffer list in one go and/or quick file-oriented tasks like search-and-replace.

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.