【问题标题】:How do I open a file in VS Code terminal by partially matching the file name?如何通过部分匹配文件名在 VS Code 终端中打开文件?
【发布时间】:2018-10-08 17:12:20
【问题描述】:

如果我有一个名为 w5_align_example.cpp 的文件,如何仅通过提供单词 align 在 VS Code 集成终端中打开该文件?

code w5_align_sample.cpp 会打开它,但我有时只记得关键字align,除非我在单独的命令中搜索以查看文件的开头。我想用一个命令打开。

我试过了:

  • $ ls | grep "align" | code 这给了我Run with 'code -' to read output from another program (e.g. 'echo Hello World | code -'). 错误。

  • $ ls | grep "align" | code - 打开一个名为code-stdin-sfd.txt 的新文件,其中包含文本w5_align_example.cpp

最简单(即最短)的命令是什么?

【问题讨论】:

    标签: bash terminal visual-studio-code


    【解决方案1】:
    ls | grep "align" | xargs -I{} code {}
    

    code $(ls | grep "align")
    

    【讨论】:

      【解决方案2】:

      您可以使用*。它匹配任何字符串并且可以多次使用。

      code *align*
      

      在某些 shell 中,您可以将其与制表符完成结合使用。只需输入:

      code *align*
      

      然后按 Tab。这将填写文件名的其余部分,但如果有多个选项,它会发出哔哔声。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-11
        • 2021-04-26
        • 1970-01-01
        • 2021-04-30
        • 1970-01-01
        • 2011-06-28
        • 2023-01-11
        • 1970-01-01
        相关资源
        最近更新 更多