Search code examples
vimvi

In vim, how do you add files from the buffer list - that match a pattern - to the arguments list?


Say I had opened vim with no arguments, then from within vim opened 10 .txt files and 10 .py files. Also, let's say the files are scattered around my file system. The buffer list contains all 20 files.

Now I want to add the 10 .py files to the arguments list. I want to do something like :argadd *.py, but this just creates a new file called '*.py' and adds it to the arguments list.

I see from the help that argd[elete] can use a pattern, so I could delete all the .py files with :argd *.py. Is there a way to do something similar for :arga[dd]?

:[count]arga[dd] {name} ..
            Add the {name}s to the argument list.  

:argd[elete] {pattern} ..
            Delete files from the argument list that match the
            {pattern}s.

Surely there's a better way than navigating to each .py file and running :argadd?


Solution

  • You can go through all your buffers and add them to the argument list based on some discriminant with a single easy command:

    :bufdo if &ft == 'python' | argadd | endif
    

    or, if you really don't like typing:

    :bufdo if&ft=='python'|arga|en
    

    See :help :bufdo.