語法參考資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面詳細說明程式碼搜尋支援的篩選器、運算子、語法選項和鍵盤快速鍵。
支援的篩選器
下表列出您可在搜尋程式碼時使用的篩選器。
篩選器 |
其他選項 |
說明 |
範例 |
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:
篩選器支援的常用程式設計語言。如適用,可為值使用別名。
語言 |
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 |
|
Rust |
rust |
rs |
殼層 |
shell |
bash 、sh |
SHTML |
shtml |
|
SQL |
sql |
|
Swift |
swift |
|
TCL |
tcl |
|
XML |
xml |
|
XSLT |
xslt |
|
YAML |
yaml |
|
支援的運算子
下表列出您在搜尋程式碼時可使用的運算子。
其他語法選項
搜尋程式碼時,系統支援下列額外語法選項。
選項 |
說明 |
(search_expression) |
將多個字詞分組。將搜尋字詞分組。 |
- |
從搜尋結果排除字詞。 |
\ |
逸出特殊字元,例如 . 、\ 或 ( 。 |
「search_expression」 |
執行常值搜尋,而不將搜尋查詢解讀為規則運算式。 |
支援的鍵盤快速鍵
如要查看 Code Search 提供的鍵盤快速鍵,請輸入 ?
。
下表列出您可在搜尋程式碼時使用的鍵盤快速鍵。
金鑰 |
動作 |
小時 |
顯示檔案的修訂版本記錄。 |
q |
開啟或關閉底端面板。 |
b |
顯示或隱藏 blame 層。 |
f |
顯示尋找列。 |
/ |
將焦點移至搜尋框。 |
o |
將焦點移至大綱瀏覽器。 |
t |
將焦點移至目錄樹。 |
l |
開啟「連結」下拉式選單。 |
lp |
複製「連結」下拉式選單中的檔案路徑。 |
lh
|
在「連結」下拉式選單中,複製檔案的 HEAD 版本連結。 |
lr
|
在「連結」下拉式選單中,複製檔案目前版本和目前行的連結。 |
.
|
在搜尋框中,搜尋目前目錄中的程式碼或檔案。 |
j |
選取搜尋結果中的下一項結果。 |
k |
在搜尋結果中選取上一項結果。 |
x |
顯示符號的交叉參考資料。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-28 (世界標準時間)。
[null,null,["上次更新時間: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. |"]]