> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/077-how-to-search-in-an-overleaf-project.md).

# 如何在 Overleaf 项目中搜索

本文介绍了在 Overleaf 项目中搜索文本的两种方式。

* [**在当前文件中查找和替换**](#search-and-replace-within-the-current-file) 可让你在编辑器中当前打开的可编辑文件内查找并替换文本。
* [**项目范围搜索**](#project-wide-search) 可让你在项目中的所有文本文件中进行搜索。

## 在当前文件中查找和替换

此功能可让你在编辑器中显示的可编辑文件内查找并替换文本。此功能不适用于只读文件，例如：

* 文本文件 [从外部 URL 上传的](/latex/zh-cn/zhi-shi-ku/081-how-to-upload-a-file-using-an-external-url.md)，包括存储在 Google Drive 中的文件，以及 `.bib` 从以下位置导入的文件（参考库） [Papers](/latex/zh-cn/zhi-shi-ku/071-how-to-link-papers-to-your-overleaf-account.md), [Mendeley](/latex/zh-cn/zhi-shi-ku/070-how-to-link-mendeley-to-your-overleaf-account.md)，或 [Zotero](/latex/zh-cn/zhi-shi-ku/073-how-to-link-zotero-to-your-overleaf-account.md)
* 大小超过 2MB 的文本文件，因为编辑器会将其视为只读文件

### 如何访问查找和替换

可使用以下任一方法访问此功能：

1. 键盘快捷键：

* Windows/Linux：Ctrl+f
* Mac OS：Cmd+f

3. 选择 **切换搜索** 位于编辑器上方的图标：

![显示文件搜索位置的图片](/files/96180af43e2fb0de75a2ec210405c886bc64ff7b)

任一方法都会显示位于编辑器底部的搜索面板。

![显示文件搜索面板位置的图片](/files/813a04cba48bcf114f0073e179a0cba6546eae6c)

搜索面板提供以下控件。

![显示文件搜索面板上所提供控件的图片](/files/34d2b5dc2746f8cfda0cae8adf24249495349c9a)

### 如何使用搜索或搜索和替换

1. 你可以通过选择以下一个或多个选项来配置搜索，也可以不选任何选项直接搜索。

* ![Icon for case sensitive search](/files/cd01373e11a58f17eccbf5b56006dccee74f9a6e)：使用区分大小写的搜索
* ![Icon for searching using regular expressions](/files/90b87c88510aa3d5ef0af5a1931b038e5339c4f6)：使用正则表达式
* ![Icon for whole word search](/files/941c46fc795f185d0f5dc1b964a83abec1e8d49d)：仅搜索完整单词
* ![Icon for searching within selected text](/files/5758b8edf9e0b07a5b87ca1f044a33900938d0d6)：仅搜索编辑器中高亮显示的文本

3. 选择搜索选项后，在标有以下内容的框中输入搜索词： **搜索**。Overleaf 会在你输入时开始搜索，并高亮显示第一个匹配结果。
4. 使用“下一个”和“上一个”按钮查找更多搜索结果。

![显示上一个和下一个搜索结果控件的图片](/files/623ffdf5ad9a1d7aae19bd823add250f13e1e80b)

6. 若要替换搜索结果中的文本，请在以下位置输入替换文本： **替换为** 并使用以下任一方法：

* *手动替换*：选择 **替换** 即可更新单个匹配项，并使 Overleaf 高亮显示下一个匹配项。继续使用“上一个/下一个”按钮在结果间导航，并点击 **替换** 即可更新更多匹配项。
* *自动替换*：选择 **全部替换** 即可一次性替换所有匹配项。

8. **注意**：选择搜索按钮（![A button to access project-wide search](/files/fda33d859819eff0cdce88835bc7ed3a1399510f)）会切换到项目范围搜索。

## 项目范围搜索

此功能可让你在项目的所有文件中搜索文本，前提是它们都小于 2MB。大于 2MB 的文件会被排除在搜索结果之外（参见 [视频](#video-demonstrating-project-wide-search) 中的示例）。

### 如何访问项目范围搜索

可使用以下任一方法访问此功能：

1. 键盘快捷键：

* Windows/Linux：Ctrl+Shift+f
* Mac OS：Cmd+Shift+f

3. 选择 **搜索** 位于文件树上方的图标：

![显示项目范围搜索图标位置的图片](/files/c5761ac5339723072323d2f7d7c7685bc32d2f98)

5. 选择搜索按钮（![A button to access project-wide search](/files/fda33d859819eff0cdce88835bc7ed3a1399510f)）位于 [搜索面板](#how-to-access-search-and-replace).

以上任一方法都会显示一个搜索框，并暂时隐藏文件树。

![显示项目范围搜索框的图片](/files/e26a5064c173512a29cceafd1fb8d64112f4ad96)

### 如何使用项目范围搜索

1. 你可以通过选择以下一个或多个选项来配置搜索，也可以不选任何选项直接搜索。

![显示配置项目范围搜索控件的图片](/files/32ba7c4bc982c8f1653764e746250b3ecfff1ab1)

* ![Icon for case sensitive search](/files/cd01373e11a58f17eccbf5b56006dccee74f9a6e)：使用区分大小写的搜索
* ![Icon for searching using regular expressions](/files/90b87c88510aa3d5ef0af5a1931b038e5339c4f6)：使用正则表达式
* ![Icon for whole word search](/files/941c46fc795f185d0f5dc1b964a83abec1e8d49d)：仅搜索完整单词

4. 在提供的框中输入搜索词，并选择搜索图标（![Image showing project-wide search icon](/files/4fa34073ad03b04754f5d3221b967ca95d17978b)），或按回车键。
5. 任何搜索结果都会按文件列出并分组。
6. 选择某个搜索结果可跳转到相应的文件位置。

### 演示项目范围搜索的视频

下面的视频演示了如何使用 Overleaf 项目 [Typeset，这是 TeX、e-TeX 或 pdfTeX 的源代码文档](https://www.overleaf.com/latex/examples/typeset-the-source-code-documentation-for-tex-e-tex-or-pdftex/qkgfgyspnhcv)。选择该项目是因为它包含较大的 `.tex` 文件，包括 `pdftex.tex`，其大小超过 2MB 限制，因此被排除在搜索结果之外。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/21dsGfzi4yynX5beA2eBz3/4bd76333ece5ae522e09bb9745b8d6ca/NewSearch.mp4>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/077-how-to-search-in-an-overleaf-project.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
