Populate arglist with files, exclude directories

60 views
Skip to first unread message

Jason Franklin

unread,
Jan 5, 2020, 10:49:52 AM1/5/20
to vim_use
Greetings,

I'm having trouble finding a clean way to do this...

In a project directory, I will often use the command below to populate the arglist:

  :args **

This works okay, but it includes directories in the arglist which will be opened with netrw.

Is there a concise, clean method to omit directories from the arglist when populating it with
all files below the current project directory?

--
Jason Franklin

Tim Chase

unread,
Jan 5, 2020, 4:01:02 PM1/5/20
to Jason Franklin, vim...@googlegroups.com
On 2020-01-05 06:28, Jason Franklin wrote:
> Is there a concise, clean method to omit directories from the
> arglist when populating it with all files below the current project
> directory?

I was unable to find anything inherent to the "**" token, but at
least on *nix-like platforms you might be able to use

:args `find . -type f`

as detailed at

:help backtick-expansion

If you're stuck on Windows without a find(1) command, you *should*
*in theory* be able to do it in pure vim with a bit more typing:

:args `=filter(expand('**', v:true, v:true), '!isdirectory(v:val)')`

because

:echo filter(expand('**', v:true, v:true), '!isdirectory(v:val)')

returns the right results. However I'm not getting this to work.
Can another set of eyes confirm if this is a bug? I'm basing my
determination on

:help `=
"""
You can have the backticks expanded as a Vim expression, instead of
as an external command, by putting an equal sign right after the
first backtick
...
When the result is a |List| then each item is used as a name.
"""

So I would expect the ":args `=…`" to work because the filter()
returns a list according to type().

Am I missing something?

-tim





Johannes Degen

unread,
Jan 5, 2020, 4:27:53 PM1/5/20
to vim...@googlegroups.com
:args `=filter(expand('**', v:true, v:true), '!isdirectory(v:val)')` works for me (Vim 8.2.74 on OpenBSD 6.6). If you checked on Windows it might mean a Windows related bug(?)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200105150052.494caa75%40bigbox.attlocal.net.


--
When in doubt become a philosopher.

Tim Chase

unread,
Jan 5, 2020, 4:41:33 PM1/5/20
to Johannes Degen, vim...@googlegroups.com
On 2020-01-05 22:27, Johannes Degen wrote:
> :args `=filter(expand('**', v:true, v:true),
> '!isdirectory(v:val)')` works for me (Vim 8.2.74 on OpenBSD 6.6).
> If you checked on Windows it might mean a Windows related bug(?)

Did you get more than one result? I only got one file, testing on
FreeBSD & OpenBSD:

$ mkdir -p ~/tmp/v/{a,b}
$ for d in ~/tmp/v/{a,b,} ; echo "$d" > "$d/foo.txt" ; done
$ cd ~/tmp/v
$ vim
:args `=filter(expand('**', v:true, v:true), '!isdirectory(v:val)')`

this opens foo.txt but

:args

shows that it's the only file in the arg-list, missing "a/foo.txt" and
"b/foo.txt"

whereas

:args `find . -type f`
:args

shows all the expected files.

-tim


Richard Mitchell

unread,
Jan 5, 2020, 7:46:15 PM1/5/20
to vim_use
What shell are you using?  I'm guessing bash?  Time to update to zsh

  ls *(.)

will list only regular files.  conversely

  ls -d *(/) will list only directories.

zsh is to bash what tcsh was to csh, but a couple magnitudes more.  oh-my-zsh and iterm2 (if OS X) and you'll never look back.

Johannes Degen

unread,
Jan 6, 2020, 9:00:50 AM1/6/20
to vim...@googlegroups.com
It might be a shell thing. I use zsh and yes, I got all the results I expected.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Jason Franklin

unread,
Jan 6, 2020, 6:58:43 PM1/6/20
to vim_use
I appreciate the responses from everyone.

However, it seems that the answer to my original question is "no".  There does not appear to be a concise way to do this from the command line.

Thanks!

--
Jason Franklin
To unsubscribe from this group and stop receiving emails from it, send an email to vim...@googlegroups.com.

Ben Fritz

unread,
Jan 7, 2020, 9:42:03 AM1/7/20
to vim_use
Do all the files of interest have an extension in their name? If so, maybe ":args ./**/*.*"

Johannes Degen

unread,
Jan 8, 2020, 2:19:34 PM1/8/20
to vim...@googlegroups.com

>On Tue, Jan 7, 2020 at 3:42 PM Ben Fritz <fritzo...@gmail.com> wrote:
>Do all the files of interest have an extension in their name? If so, maybe ":args ./**/*.*"

Nice and pretty clean solution!
Reply all
Reply to author
Forward
0 new messages