6

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)?

10

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.

  • 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 Apr 18 '15 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 Apr 18 '15 at 23:48
  • Re: globstar, I've performed some small testing in here. – kenorb Apr 19 '15 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 Mar 16 '18 at 17:13
  • 1
    @alpha_989 Have you tried to escape it (\|)? – kenorb Mar 16 '18 at 17:15

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.