generated from timlrx/tailwind-nextjs-starter-blog
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vimpas
committed
Sep 13, 2024
1 parent
22149f0
commit ddce92f
Showing
8 changed files
with
500 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"next-js":1,"react":1,"javascript":1,"web开发":1} | ||
{"ssh":1,"vim":1,"剪切板同步":1,"远程服务器":1,"neovim":1,"next-js":1,"react":1,"javascript":1,"web开发":1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
title: ssh连接远程服务器neovim剪切板同步问题 | ||
summary: 本文探讨了在SSH连接远程服务器时使用Neovim并实现与本地剪切板同步的几种方法。主要介绍了三种解决方案:使用SSH X11转发、利用tmux和OSC52序列,以及使用第三方工具。每种方法都有其优缺点和适用场景,文章详细说明了各种方法的实现步骤和注意事项,为用户提供了多种选择以满足不同的需求和环境。 | ||
date: '2024-05-08' | ||
tags: ['ssh', 'vim', '剪切板同步', '远程服务器', 'Neovim'] | ||
draft: false | ||
--- | ||
|
||
<TOCInline toc={props.toc} exclude="Introduction" /> | ||
|
||
|
||
要在远程服务器上使用 Neovim 并且与本地剪切板同步,你需要通过 SSH 使用 X11 转发或者使用专门的工具来实现剪切板内容的传输。 | ||
|
||
以下是几种实现远程 Neovim 剪切板同步到本地的方法: | ||
|
||
### 方法 1: 使用 SSH X11 Forwarding | ||
|
||
如果你用的是 X11 环境(通常是在 Linux 上),可以使用 SSH 的 X11 转发功能来实现。 | ||
|
||
{/* [[什么是X11和ssh的X11转发功能]] */} | ||
|
||
1. 确保本地机器和远程服务器都安装了 `xclip` 或 `xsel`。 | ||
2. 使用 `-X` 或 `-Y` 参数启动 SSH 会话来启用 X11 转发: | ||
|
||
```sh | ||
ssh -X username@remote_host | ||
``` | ||
|
||
或者 | ||
|
||
```sh | ||
ssh -Y username@remote_host | ||
``` | ||
|
||
`-Y` 参数比 `-X` 更不安全,但在某些配置的服务器上可能需要。 | ||
|
||
3. 在远程服务器上的 Neovim 中,你需要有类似以下的配置: | ||
|
||
```vim | ||
set clipboard=unnamedplus | ||
``` | ||
|
||
这样设置后,Neovim 中的 `"+y` 和 `"+p` 将会使用系统的剪切板,借助 SSH 的 X11 转发同步到你的本地机器。 | ||
|
||
请注意,SSH X11 转发可能会有安全风险,并且在网络延迟较高的情况下可能会有性能问题。 | ||
|
||
### 方法 2: 使用 tmux 和 OSC52 | ||
|
||
如果你正在使用 tmux,可以通过 ANSI Escape sequences 实现剪切板同步,这里使用的是特定的序列 OSC52。 | ||
|
||
1. 确保你的本地终端支持 OSC52 (比如 iTerm2 或者是最新版本的 Terminal.app)。 | ||
2. 设置 Neovim,使其能够发送 OSC52 序列。这通常需要一个自定义函数,并将其绑定到 Neovim 的复制操作。 | ||
|
||
在 Neovim 中,你可以使用以下 Vimscript 来发送选中的文本到 OSC52: | ||
|
||
```vim | ||
function! CopyToClipboard(text) abort | ||
let escape = "\e" | ||
let osc = escape . "[52;c;" | ||
let st = escape . "\" | ||
let data = system('echo ' . a:text . ' | base64') | ||
let payload = osc . data . st | ||
if has('nvim') | ||
call rpcnotify(0, 'Gui', 'Do', payload) | ||
else | ||
echoerr 'Not supported in this environment' | ||
endif | ||
endfunction | ||
``` | ||
|
||
然后,你需要设置一个自动命令或键位绑定,将复制操作触发时的文本传递给这个函数。 | ||
|
||
此方法的具体实现可能会根据你的需求和环境有所不同,可能需要一些调试才能正常工作。 | ||
|
||
### 方法 3: 使用第三方工具 | ||
|
||
还有一些第三方工具(如 `lemonade`, `xclip`, `win-clipboard` 等)可以帮助实现远程服务器和本地机器之间的剪切板同步。 | ||
|
||
以 `lemonade` 为例,你可以在远程服务器上安装它,并在本地运行其服务器端。然后设置 Neovim,使其使用 `lemonade` 来复制和粘贴文本。 | ||
|
||
安装并使用这些工具的具体步骤会因工具而异,你可以查阅对应工具的文档以获取详细信息。 | ||
|
||
### 结论 | ||
|
||
选择哪种方法取决于你的具体环境和需求。X11 转发更适合 Linux 用户,而 tmux 的 OSC52 方法和第三方工具则更加通用,但可能需要更多的配置。在尝试这些方法之前,请确保了解其安全性和性能影响,并确保你的环境支持所需的功能k。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.