语法参考文档
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页详细介绍了代码搜索支持的过滤条件、运算符、语法选项和键盘快捷键。
支持的过滤器
下表列出了搜索代码时可以使用的过滤条件。
过滤 |
其他选项 |
说明 |
示例 |
case:yes |
case:y |
使搜索区分大小写。默认情况下,搜索不区分大小写。
如果把多个搜索字词分组到一起,则所有子组都会继承此过滤条件。 |
case:yes Hello World |
class: |
|
搜索类名称。 |
class:MainClass |
comment: |
|
在评论中搜索。 |
comment:bug |
content: |
|
仅搜索文件内容。这会排除文件名。 |
content:hello |
file: |
filepath:
path:
f: |
按文件名或路径搜索文件。 |
file:test.js |
function: |
func: |
搜索函数名称。 |
function:print |
lang: |
language: |
使用特定的语言搜索结果。 |
lang:java test |
pcre:yes |
|
使用与 Perl 兼容的正则表达式。
可用于跨行搜索。 |
pcre:yes @Provides\s+double |
symbol: |
|
搜索特定符号。 |
symbol:immutable |
usage: |
|
搜索时排除注释和字符串字面量。 |
usage:map |
语言选项
下表列出了 lang:
过滤条件支持的常用编程语言。在适用的情况下,可以使用值的别名。
语言 |
lang: 值 |
别名 |
C++ |
c++ |
cpp 、cc 、cxx |
C |
c |
|
Java |
java |
|
Kotlin |
kotlin |
kt 、kts |
Python |
python |
py |
JavaScript |
javascript |
js |
Go |
go |
golang |
JSON |
json |
|
HTML |
html |
angular |
Objective-C++ |
objectivec++ |
|
Objective-C |
objectivec |
objc |
Markdown |
markdown |
md |
AppleScript |
applescript |
|
C# |
c# |
csharp |
CSS |
css |
|
CSV |
csv |
|
curl |
curl |
|
Dart |
dart |
|
Django |
django |
|
JSP |
jsp |
|
Perl |
perl |
|
PHP |
php |
|
PowerShell |
powershell |
|
Ruby |
ruby |
|
Rust |
rust |
rs |
shell |
shell |
bash 、sh |
SHTML |
shtml |
|
SQL |
sql |
|
Swift |
swift |
|
TCL |
tcl |
|
XML |
xml |
|
XSLT |
xslt |
|
YAML |
yaml |
|
支持的运算符
下表列出了搜索代码时可以使用的运算符。
其他语法选项
搜索代码时,还支持以下其他语法选项。
选项 |
说明 |
(search_expression) |
将多个字词分组到一起。如需了解详情,请参阅将搜索字词分组。 |
- |
从搜索结果中排除该字词。 |
\ |
对特殊字符进行转义,如 . .\ 、或 ( |
“search_expression” |
执行字面搜索,而不将搜索查询解释为正则表达式。 |
支持的键盘快捷键
如需查看代码搜索中可用的键盘快捷键,请键入 ?
。
下表列出了搜索代码时可以使用的键盘快捷键。
密钥 |
操作 |
小时 |
显示文件的修订历史记录。 |
q |
切换底部面板。 |
b |
显示或隐藏 blame 层。 |
f |
显示查找栏。 |
/ |
将焦点移至搜索框。 |
o |
将焦点移至大纲浏览器。 |
t |
将焦点更改为目录树。 |
l |
打开“链接”下拉菜单。 |
lp |
复制“链接”下拉菜单中的文件路径。 |
lh
|
复制“链接”下拉菜单中指向该文件的 HEAD 版本的链接。 |
lr
|
在“链接”下拉菜单中复制指向该文件的当前版本和当前行的链接。 |
.
|
在搜索框中时,在当前目录中搜索代码或文件。 |
j |
选择搜索结果中的下一个结果。 |
k |
选择搜索结果中的上一个结果。 |
x |
显示符号的交叉引用。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-28。
[null,null,["最后更新时间 (UTC):2025-08-28。"],[[["\u003cp\u003eCode Search allows you to search for code using filters like \u003ccode\u003elang:\u003c/code\u003e, \u003ccode\u003efile:\u003c/code\u003e, and \u003ccode\u003eclass:\u003c/code\u003e to refine your results by language, filename, or class name respectively.\u003c/p\u003e\n"],["\u003cp\u003eYou can use operators like \u003ccode\u003eAND\u003c/code\u003e and \u003ccode\u003eOR\u003c/code\u003e to combine search terms, along with additional syntax options for grouping, excluding, and escaping characters within your queries.\u003c/p\u003e\n"],["\u003cp\u003eCode Search supports keyboard shortcuts for actions such as showing file history (h), toggling the bottom panel (q), and navigating search results (j/k).\u003c/p\u003e\n"],["\u003cp\u003eA wide variety of common programming languages are supported by Code Search, including but not limited to: Python, Java, JavaScript, C++, Go, and more, which can be specified using the \u003ccode\u003elang:\u003c/code\u003e filter and their respective values or aliases.\u003c/p\u003e\n"]]],[],null,["This page provides detailed information on the supported filters, operators,\nsyntax options, and keyboard shortcuts for Code Search.\n\nSupported filters\n\nThe following table lists the filters you can use when searching code.\n\n| Filter | Other options | Description | Example |\n|-------------|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|\n| `case:yes` | `case:y` | Make the search case sensitive. By default, searches are not case sensitive. If you are grouping multiple search terms, this filter is inherited by all child groups. | `case:yes Hello World` |\n| `class:` | | Search for a class name. | `class:MainClass` |\n| `comment:` | | Search within comments. | `comment:bug` |\n| `content:` | | Search only for file contents. This excludes filenames. | `content:hello` |\n| `file:` | `filepath:` `path:` `f:` | Search for a file by filename or path. | `file:test.js` |\n| `function:` | `func:` | Search for a function name. | `function:print` |\n| `lang:` | `language:` | Search for results by using a specific language. | `lang:java test` |\n| `pcre:yes` | | Use Perl compatible regular expressions. Useful for searching across lines. | `pcre:yes @Provides\\s+double` |\n| `symbol:` | | Search for a specific symbol. | `symbol:immutable` |\n| `usage:` | | Search while excluding comments and string literals. | `usage:map` |\n\nlang options\n\nThe table below lists the commonly used programming languages supported by the\n`lang:` filter. Where applicable, an alias can be used for the value.\n\n| Language | `lang:` value | Aliases |\n|---------------|----------------|--------------------|\n| C++ | `c++` | `cpp`, `cc`, `cxx` |\n| C | `c` | |\n| Java | `java` | |\n| Kotlin | `kotlin` | `kt`, `kts` |\n| Python | `python` | `py` |\n| JavaScript | `javascript` | `js` |\n| Go | `go` | `golang` |\n| JSON | `json` | |\n| HTML | `html` | `angular` |\n| Objective-C++ | `objectivec++` | |\n| Objective-C | `objectivec` | `objc` |\n| Markdown | `markdown` | `md` |\n| AppleScript | `applescript` | |\n| C# | `c#` | `csharp` |\n| CSS | `css` | |\n| CSV | `csv` | |\n| curl | `curl` | |\n| Dart | `dart` | |\n| Django | `django` | |\n| JSP | `jsp` | |\n| Perl | `perl` | |\n| PHP | `php` | |\n| PowerShell | `powershell` | |\n| Ruby | `ruby` | |\n| Rust | `rust` | `rs` |\n| shell | `shell` | `bash`, `sh` |\n| SHTML | `shtml` | |\n| SQL | `sql` | |\n| Swift | `swift` | |\n| Tcl | `tcl` | |\n| XML | `xml` | |\n| XSLT | `xslt` | |\n| YAML | `yaml` | |\n\nSupported operators\n\nThe following table lists the operators you can use when searching code.\n\n| Operator | Description |\n|----------|--------------------------------------------------------------------------------------------------------------|\n| `AND` | Logical \\`AND\\` operator. See [Using the AND operator](/code-search/user/and-operator) for more information. |\n| `OR` | Logical \\`OR\\` operator. See [Using the OR operator](/code-search/user/or-operator) for more information. |\n\nAdditional syntax options\n\nThe following additional syntax options are supported for searching code.\n\n| Option | Description |\n|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------|\n| (\u003cvar translate=\"no\"\u003esearch_expression\u003c/var\u003e) | Groups multiple terms together. See [Grouping search terms](/code-search/user/group-terms) for more information. |\n| `-` | Excludes the term from search results. |\n| `\\` | Escapes special characters such as `.`, `\\`, or `(`. |\n| \"\u003cvar translate=\"no\"\u003esearch_expression\u003c/var\u003e\" | Perform a literal search without interpreting the search query as a regular expression. |\n\nSupported keyboard shortcuts\n\nTo see the keyboard shortcuts available in Code Search, type `?`.\n\nThe following table lists the keyboard shortcuts you can use when searching\ncode.\n\n| Key(s) | Action |\n|--------|-------------------------------------------------------------------------------------------------|\n| h | Show the file's revision history. |\n| q | Toggle the bottom panel. |\n| b | Show or hide the blame layer. |\n| f | Show the find bar. |\n| / | Change focus to the search box. |\n| o | Change focus to the outline browser. |\n| t | Change focus to the directory tree. |\n| l | Opens the Links drop-down. |\n| lp | Copies the file path in the Links drop-down. |\n| lh | Copies the link to the HEAD version of the file in the Links drop-down. |\n| lr | Copies the link to the current version of the file and the current line in the Links drop-down. |\n| . | While in the search box, search for code or files in the current directory. |\n| j | Select the next result in the search results. |\n| k | Select the previous result in the search results. |\n| x | Show cross references for symbols. |"]]