出于某种原因,我一生都无法弄清楚在使用 vim 时如何将单引号传递给外部工具。例如,我可能想调用 Vim 的外部 grep 来搜索文本“foo”(即单引号然后是单词 foo)
所以我可能会尝试以下命令:
:grep \"foo *.txt
Run Code Online (Sandbox Code Playgroud)
但这会导致以下错误消息:
!findstr /n \"foo *.txt >C:\Users\[username]\AppData\Local\Temp\VIeC244.tmp 2>&1
shell returned 1
E40: Can't open errorfile C:\Users\[username]\AppData\Local\Temp\VIeC244.tmp
Run Code Online (Sandbox Code Playgroud)
请注意,grep 已更改为使用 'findstr /n',因为我在 Windows 上(并且可以通过运行来验证echo &grepprg)。我发现如果我自己从命令行输入以下内容,我可以轻松地执行我想要的搜索:
findstr /n \"foo *.txt
Run Code Online (Sandbox Code Playgroud)
这完全符合我的预期
您可以尝试暂时(或永久)将 'shellxquote' 设置为单引号字符,例如:set shellxquote=\"
请注意,这会破坏一些使用特殊字符的外部命令,如 &、|、<、> 等(默认情况下 shellxescape 中的所有内容),因此您可能不需要将其保留为该值。但是,看起来这是 Vim 7.3.450 中默认 shellxquote 值被破坏的地方。
| 归档时间: |
|
| 查看次数: |
1076 次 |
| 最近记录: |