7

The following command works as expected within vim:

:args `find . -type f`

as well as this one (with wildcard):

:args `find . -name \*.inc`

However when I run the following:

:args `find . -type f -not -path "*/\.*"`

I've the error:

E79: Cannot expand wildcards

"`find . -type f -not -path" [New File]

It works from the command line as expected:

$ find . -type f -not -path "*/\.*"

Basically the extra -not -path "*/\.*" means to ignore all the hidden files starting with dot, such as git repository files.

What I'm doing wrong? Do some characters needs to be escaped (which one)?

1
  • More words about the E79. For this case, find returning error code let vim raise the E79 message. This is not the same thing as help E79 described. For instance, :args `false` also gets an E79, and it has nothing to do with expanding wildcard. Commented Jun 8, 2022 at 11:31

1 Answer 1

11

You were close. Enclose the path pattern in single quotes instead of double quotes for the find command like so:

args `find . -type f -not -path '*/\.*'`

By the way, a handy way to ignore hidden files is to use :args **. But this will include folders too.

I'm not completely sure why you need to enclose it in single quotes, I believe that Vim will evaluate the special characters inside double quotes. See :help expr-quote and :help literal-string. A single quote will treat the pattern as a literal string and prevent Vim evaluating special characters inside the quote.

In this case, since \. is one of the special characters Vim will evaluate in a double quoted string, I believe this was the culprit.

7
  • 1
    Thanks, I didn't think of single-quote, it was too close:) Regarding glob pattern (**) it works for bash and zsh, only when globstar is set, so sometimes it's not set by default. And it include also the folders. But it's a great substitute:) This one {,**/}*.* will exclude folders (bash4).
    – kenorb
    Commented Apr 18, 2015 at 23:25
  • Yep, you're right, args ** does include folders. You can always give it extensions (:args *.h *.cpp etc) to search for, so that it's both faster and will only find files. Amended my answer though.
    – akshay
    Commented Apr 18, 2015 at 23:48
  • Re: globstar, I've performed some small testing in here.
    – kenorb
    Commented Apr 19, 2015 at 14:36
  • @kenorb, I am trying to run this command: vim /undo/g `find /home/dibya \( -type f -regextype posix-extended -regex '.* vim|.*md' \)`
    – alpha_989
    Commented Mar 16, 2018 at 17:13
  • 1
    @alpha_989 Have you tried to escape it (\|)?
    – kenorb
    Commented Mar 16, 2018 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.