请问 VS Code 如何查找指定目录下,指定类型文件中是否包含关键字?

200 天前
 gangsta
比如查找 src 目录下所有的.sql 后缀文件中是否“CREATE TABLE”这一搜索关键词,听起来是一个很常见的需求

1. 通常我是在想要搜索的目录上选择 [在文件夹中查找 / ⌥ + ⇧ + F ] ,但此时 vs code 会自动将该文件夹路径回填到 [包含的文件] 下面的输入框中,没法填写过滤文件类型了 (输入空格+文件类型也不行);

2. 直接输入搜索词,然后 [包含的文件] 输入框中输入“.sql”,此时倒是可以过滤文件类型,但是搜索是针对整个编辑器的 workspace ,速度和效率又不太理想,还要过滤一大堆不相关结果

请问是否有什么设置或者插件可以满足?

1980 次点击
所在节点    Visual Studio Code
25 条回复
CEBBCAT
200 天前
使用这条命令:

grep -Rn ./src -e 'CREATE TABLE' '--include=*.sql'

搜索方式:Google “shell find file contain text”
会把你带到 https://stackoverflow.com/a/16957078
---
BTW, IntellIJ 的 Find Tool 也可以完成这个工作
liuhan907
200 天前
@gangsta include 是可以包含目录的
cchaan
200 天前
windows 下我的 EmEditor ,文件夹空白右键“用 EmEditor 在文件中查找”,是用的最顺手的
GreatAuk
200 天前
@gangsta 了解一下 glob
runze
200 天前
https://code.visualstudio.com/docs/editor/glob-patterns

VS Code supports the following glob syntax:

/ to separate path segments
* to match zero or more characters in a path segment
? to match on one character in a path segment
** to match any number of path segments, including none
{} to group conditions (for example {**/*.html,**/*.txt} matches all HTML and text files)
[] to declare a range of characters to match (example.[0-9] to match on example.0, example.1, …)
[!...] to negate a range of characters to match (example.[!0-9] to match on example.a, example.b, but not example.0)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/987303

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX