3

I have encountered very strange problem using vimgrep command. I try to find a match in all the files in all subdirs of a specified directory:

:vimgrep /word_I_search/ path\to\my\dir\**\*

(there are backslashes in path because I am on Windows). Command reports:

E480: No match: word_I_search

But I know there are matches! And if I do not search in subdirs or if I start searching one level higher everything is ok. Following commands successfully find what I want:

:vimgrep /word_I_search/ path\to\my\dir\*
:vimgrep /word_I_search/ path\to\my\**\*

I have never encountered this problem on my Linux machine and do not know where to start troubleshooting it. Any ideas? Please help.

UPDATE:

command works as expected if I use less backslashes. Following commands work as expected:

:vimgrep /word_I_search/ path/to/my/dir/**/*
:vimgrep /word_I_search/ path\to\my\dir\**/*
2
  • 1
    You don't need to use backslashes.
    – romainl
    Aug 18, 2016 at 8:05
  • 1
    Thanks, @romani! The problem is that slashes are automatically replaced by backslashes when I press <tab> to autocomplete path. But looks like I found workaround.
    – lesnik
    Aug 18, 2016 at 8:11

2 Answers 2

2

So to conclude, one has to do:

 :vimgrep /text/ path_to_dir/* path_to_dir/**/*

if he wants to include the dir.

1
  • Thanks for this. In my case, I was forgetting to add the trailing slash after /text before specifying the path to search for this text in. Sep 26, 2023 at 20:27
1

** matches only directories as you can read in http://vimdoc.sourceforge.net/htmldoc/editing.html#file-searching, but obviously at least 1 subdirectory if you are using backslashes in your path. I.e. ** matches not 0..n but 1..n subdirectories. (Again) this is true only when you are using backslashes in your search path.

3
  • I think in the context of vimgrep this is not true. See the linked documentation. It talks about a few functionalities and adds: "Other commands use |wildcards| which is slightly different.". Also: I couldn't reproduce the problem on Windows7 with Vim 8.1.751.
    – Ralf
    Jan 18, 2019 at 15:36
  • I wrote obviously in the anser above because I could reproduce this issue on Win10 with a x64 build of Vim 8.0 (2016 Sep 12). After some testing, I concluded that it matters if you use forward- or backslashes and if you use \, vimgrep needs to match at least one subdirectory.
    – salchint
    Jan 18, 2019 at 15:48
  • @sachint The important part is the first 2 sentences. Vimgrep uses wildcards, not file-searching.
    – Ralf
    Jan 18, 2019 at 16:27

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.