:let &grepprg = "echo 'grep: $*'" " Adjust 'grepprg' for ease of inspection. :grep % <cWORD> `="string"` :!echo 'grep: % <cWORD> `="string"`' " Note: This produces identical output.
Assuming a current file name of
current-file.txt and that the cursor is on WORD
:grep command above outputs:
grep: current-file.txt current-WORD `="string"`
The first two arguments to
:grep (interpreted by
:h cmdline-special) were expanded, but the
`= expression was not. Since
:grep can accept file name arguments, can someone please clarify why only
:h cmdline-special expansion was performed? My research into the docs is documented below.
:h cmdline-special states that strings like
<cWORD> are expanded "at places where a file name can be used":
In Ex commands, at places where a file name can be used, the following characters have a special meaning. These can also be used in the expression function expand().
This explains why commands which do not expect a file name (e.g.
:normal) do not perform this expansion:
:normal % " Has same effect as typing "%" in normal mode
Now, looking at the docs for
:h `=, the first line states
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, e.g:
which seems to suggest that
:h `= expansion applies in the same context as
:h `-expansion states:
On Unix and a few other systems you can also use backticks for the file name argument, for example:
:next `find . -name ver\\*.c -print` :view `ls -t *.patch \| head -n1`
Thus, it seems that all forms of expansion mentioned in this post (
:h `-expansion) apply to all
file name arguments, but the
:grep example illustrated that it is not so.
Is my interpretation of the docs incorrect or is there more to the notion of "file name argument"? Short of looking at the Vim source code, is there another resource which addresses this discrepancy?