I have two files open, say File.h and File.m in separate tabs.

| File.h         |  File.m        |

:ls reveals

  1 %a   "File.h" line 1
  2  a   "File.m" line 0

When I run

:bufdo set fo=croql

I suddenly have two tabs with the same content

| File.m         |  File.m        |

but :ls gives the output

  1 #    "File1.h" line 1
  2 %a   "File2.m" line 1

I don't understand from the documentation what the # char means here, except that I can :e # to get back to the initial configuration.

Can somebody elucidate what is happening here?

  • 1
    :bufdo doesn't know about tabs, it opens every buffer in the current tab and runs your command on it. The # refers to the "alternate file name", which is the "last file name" AFAIK. It's to easily switch between 2 files (like cd -). This is a "buffer-based workflow" versus a "tab-based workflow" thing (they don't always mix very well). – Martin Tournoij Jul 28 '15 at 12:52
  • I see. So in this case tabdo would be the way to go. – oarfish Jul 28 '15 at 13:07
  • Perhaps also use setlocal instead of set? It doesn't make much sense to set the same global option several times. – Sato Katsura Jul 28 '15 at 20:58

:help :bufdo explains very clearly how :bufdo works:


The last buffer to be visited becomes the current buffer (%), and the buffer visited just before becomes the alternate buffer (#).

:tabdo doesn't care about buffers so it's most likely to be the right command for you.

  • If you hate that behaviour of :bufdo then you can use my :BufDo command which returns you to the buffer you started on. – joeytwiddle Jul 29 '15 at 22:52

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.