Multiple extensions in vimgrep fail to retrieve strings correctly

Asked 2 years ago, Updated 2 years ago, 59 views

When using vimgrep with Vim, you are experiencing a problem where multiple extensions cannot correctly retrieve strings.

As a test of vimgrep operation, we have prepared the following directories:

src=

a.ca.h b.c b.h contains only the 'test' string.
The results of vimgrep in this environment are as follows:

■ If the current directory is . (transitioned to cd on vim)
vimgrep/test/**/* → 4 hits (OK: works as expected)
vimgrep/test/**/*.c → 2 hits (OK: works as expected)
vimgrep/test/**/*.h → 2 hits (OK: works as expected)
vimgrep/test/**/*.c*.h → 2 hits (NG: 4 hits should be)

■ If the current directory is D1 (transitioned to:cd on vim)
vimgrep/test/**/* → 4 hits (OK: works as expected)
vimgrep/test/**/*.c → 2 hits (OK: works as expected)
vimgrep/test/**/*.h → 2 hits (OK: works as expected)
vimgrep/test/**/*.c*.h → 3 hits (NG: 4 hits should be)

■ If the current directory is D2 (transitioned to:cd on vim)
vimgrep/test/**/* → 2 hits (OK: works as expected)
vimgrep/test/**/*.c → 1 hit (OK: works as expected)
vimgrep/test/**/*.h → 1 hit (OK: works as expected)
vimgrep/test/**/*.c*.h → 2 hits (OK: works as expected)

As a result, if you specified more than one extension for the search target, it appears that the string could not be retrieved correctly to the subdirectory.
If anyone knows the cause, I would appreciate it if you could give me some advice.

- Environment -
Ubuntu 18.04
Vim 8.1
.vimrc is empty

Thank you for your cooperation.

vim

2022-09-30 14:52

1 Answers

:vimgrepEx command has a signature of :vim[grep][!] /{pattern}/[g][j]{file}....If you want to recursively search the deep directory hierarchy, write **/*.c in the {file} section.

In other words, you can do what you want with the following commands:

vimgrep/test/**/*.c**/*.h


2022-09-30 14:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.