【问题标题】:How do I fuzzy find all files containing specific text using ripgrep and fzf and open it VSCode如何使用 ripgrep 和 fzf 模糊查找包含特定文本的所有文件并将其打开 VSCode
【发布时间】:2020-07-12 07:48:55
【问题描述】:

我有以下命令在命令行中模糊查找文件并在 VSCode 中打开选定的文件:

fzf --print0 -e | xargs -0 -r code

现在我希望能够在文件内容中搜索字符串。我可以在命令行中找到搜索到的字符串:

rg . | fzf --print0 -e

但是现在使用这个命令在 VSCode 中打开文件已经不起作用了:

rg . | fzf --print0 -e | xargs -0 -r code

因为向 VSCode 传递了一个文件名,其中包含文件名本身和搜索字符串,这当然是一个空文件。

如何结合上述两个命令将文件名传递给包含搜索字符串的 VSCode?​​p>

【问题讨论】:

  • 也许rg -l . 是吗?
  • 不行,那我只能搜索文件,不能搜索文件中的内容。

标签: visual-studio-code command-line xargs fzf ripgrep


【解决方案1】:

rg--vimgrep 选项返回医生所要求的内容。这就是我在您提出的 vscode 扩展问题请求中使用的内容:

https://github.com/rlivings39/vscode-fzf-quick-open/commit/101a6d8e44b707d11e661ca10aaf37102373c644

它返回如下数据:

$ rg --vimgrep
extension.ts:5:5:let fzfTerminal: vscode.Terminal | undefined = undefined;
extension.ts:6:5:let fzfTerminalPwd: vscode.Terminal | undefined = undefined;

然后你可以把前3个字段剪下来传给code -g

rg --vimgrep --color ansi | fzf --ansi --print0 | cut -z -d : -f 1-3 | xargs -0 -r code -g

【讨论】:

    猜你喜欢
    • 2023-02-26
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 2013-06-02
    相关资源
    最近更新 更多