# 在远程主机上编辑单个文件

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

在 [配置部署服务器](configuring-synchronization-with-a-remote-host.html)后，可以在编辑器中打开远程文件，而无需将其添加到项目中。 IntelliJ IDEA 会编辑一个临时本地副本。 上传文件以在服务器上保存更改。

调试、重构和其他一些 IntelliJ IDEA 功能不支持这类文件。 要利用高级 IntelliJ IDEA 功能，请考虑将文件包含在项目中。 有关更多信息，请参见 [访问服务器上的文件](accessing-files-on-remote-hosts.html)。

Procedure: 启用 FTP/SFTP/WebDAV Connectivity 插件

此功能依赖于 [FTP/SFTP/WebDAV Connectivity](https://plugins.jetbrains.com/plugin/13125-ftp-sftp-webdav-connectivity)插件，该插件默认在 IntelliJ IDEA 中捆绑并启用。 如果相关功能不可用，请确保您没有禁用插件。

> **Note:**
> 在未订阅 Ultimate 版的情况下，IntelliJ IDEA 中无法使用 FTP/SFTP/WebDAV 连接插件。

1. 按 `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) 打开设置，然后选择  `插件` 。

2. 找到  FTP/SFTP/WebDAV Connectivity  插件并点击   启用  。

Procedure: 在远程主机上编辑文件

1. 如果已设置 [默认远程主机](configuring-synchronization-with-a-remote-host.html#default_server)，请选择   部署 | 编辑远程文件  ，它位于 [项目

工具窗口](project-tool-window.html)、   提交  工具窗口（ `Alt+0` (Windows), `⌘ 0` (macOS), `⌘ 0` (IntelliJ IDEA Classic (macOS)), `⌘ 0` (macOS System Shortcuts), `Alt+0` (XWin), `Alt+0` (GNOME), `Alt+0` (KDE), `Alt+0` (Emacs), `Alt+0` (Sublime Text), `⌘ 0` (Sublime Text (macOS)), `Alt+0` (Visual Studio), `Alt+0` (Visual Studio (macOS)), `Alt+0` (NetBeans), `Alt+0` (Eclipse), `⌘ 0` (Eclipse (macOS))）或代码编辑器的上下文菜单中。 （ ） , or the code editor.

否则，请执行以下操作：

1.  通过从主菜单中选择  `工具 | 部署 | 浏览远程主机`  或  `视图｜工具窗口｜远程主机`  打开 [Remote Host 工具窗口](remote-host-tool-window.html)。

2.  从列表中选择所需的部署服务器。 工具窗口显示了位于  服务器根目录  下的文件和文件夹的树状视图。 如果列表中没有相关的服务器，请点击 ![浏览按钮](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.general.ellipsis.svg)，在打开的   部署  对话框中 [配置对所需服务器的访问权限](configuring-synchronization-with-a-remote-host.html)。

3.

点击该文件两次，或从上下文菜单中选择   编辑远程文件  。

![在远程主机上编辑文件](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_edit_file_on_remote_host.png)

2. 该文件会在 IntelliJ IDEA 编辑器中打开，而不会被添加或下载到本地项目中。

![在远程主机上编辑文件](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_edit_file_on_remote_host_1.png)

当您处理远程文件时，编辑器顶部会出现一个特殊工具栏，显示编辑状态（  文件与远程文件相同 或  文件已被修改。 上传？ )。

远程文件可以通过包含服务器名称的注释与本地文件区分开来（在我们的示例中，它是<MyServer>）。

![远程文件注释](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_edit_file_on_remote_host_2.png)

3. 完成文件编辑后，执行以下操作之一：

* 要将文件上传到远程主机，请点击 ![上传当前远程文件按钮](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.expui.general.upload.svg)或按 `Alt+Shift+Q` (Windows), `⌥ ⇧ Q` (macOS), `⌥ ⇧ Q` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ Q` (macOS System Shortcuts), `Alt+Shift+Q` (XWin), `Alt+Shift+Q` (GNOME), `Alt+Shift+Q` (KDE), `Alt+Shift+Q` (Emacs), `Alt+Shift+Q` (Sublime Text), `⌥ ⇧ Q` (Sublime Text (macOS)), `Alt+Shift+Q` (Visual Studio), `⌥ ⇧ Q` (Visual Studio (macOS)), `Alt+Shift+Q` (NetBeans), `Alt+Shift+Q` (Eclipse), `⌥ ⇧ Q` (Eclipse (macOS))。

* 要将当前打开的文件与上次上传的版本进行比较，请点击 ![与最后一次上传版本比较按钮](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app-client.expui.vcs.diff.svg)。 这些文件将会在 IntelliJ IDEA [文件比较查看器](differences-viewer.html) 中打开。

* 若要丢弃自上次上传后对文件所做的更改，请点击 ![](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app-client.expui.vcs.revert.svg)。

请注意，除非这些更改已上传，否则一旦您关闭文件或当前打开的项目，对单个文件的任何更改都将被丢弃。 为了防止数据丢失，IntelliJ IDEA 会在您尝试关闭已编辑文件或整个项目时显示以下对话框。

![确认上传消息](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_edit_file_on_remote_host_3.png)

## See also

### 过程

[将文件部署到服务器](deploying-applications.html)

### 参考

[远程主机工具窗口](remote-host-tool-window.html)

