1. 如何確認vim和系統剪貼板是否互通
(1) reg 查看寄存器
(2) 查看+ 和 * 2個寄存器是否有系統剪貼板的內容,如果有表示互通,如果沒有,表示沒有互通
2. 打通剪貼板
(3) 沒有互通,安裝剪貼板工具 xclip
sudo apt install xclip -y
(4) 執行第2部的步驟,檢查剪貼板狀況
neovim中關於剪切板配置的說明:
Clipboard integration *provider-clipboard* *clipboard*
Nvim has no direct connection to the system clipboard. Instead it depends on
a |provider| which transparently uses shell commands to communicate with the
system clipboard or any other clipboard "backend".
To ALWAYS use the clipboard for ALL operations (instead of interacting with
the '+' and/or '*' registers explicitly): >
set clipboard+=unnamedplus
See 'clipboard' for details and options.
*clipboard-tool*
The presence of a working clipboard tool implicitly enables the '+' and '*'
registers. Nvim looks for these clipboard tools, in order of priority:
- |g:clipboard|
- pbcopy, pbpaste (macOS)
- wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
- xclip (if $DISPLAY is set)
- xsel (if $DISPLAY is set)
- lemonade (for SSH) https://github.com/pocke/lemonade
- doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
- win32yank (Windows)
- tmux (if $TMUX is set)
*g:clipboard*
To configure a custom clipboard tool, set g:clipboard to a dictionary.
For example this configuration integrates the tmux clipboard: >
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'tmux load-buffer -',
\ '*': 'tmux load-buffer -',
\ },
\ 'paste': {
\ '+': 'tmux save-buffer -',
\ '*': 'tmux save-buffer -',
\ },
\ 'cache_enabled': 1,
\ }
If "cache_enabled" is |TRUE| then when a selection is copied Nvim will cache
the selection until the copy command process dies. When pasting, if the copy
process has not died the cached selection is applied.
g:clipboard can also use functions (see |lambda|) instead of strings.
For example this configuration uses the g:foo variable as a fake clipboard: >
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
\ '*': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
\ },
\ 'paste': {
\ '+': {-> get(g:, 'foo', [])},
\ '*': {-> get(g:, 'foo', [])},
\ },
\ }
The "copy" function stores a list of lines and the register type. The "paste"
function returns the clipboard as a `[lines, regtype]` list, where `lines` is
a list of lines and `regtype` is a register type conforming to |setreg()|.
所以我們直接使用自定義剪切板就ok,我們讓+和*寄存器都使用clipboard-provider 腳本來配置。
在neovim的配置中增加以下代碼:
neovim的配置相對較多,如果是spacevim中,可以加到~/.config/nvim/main.vim中
if executable('clipboard-provider')
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'clipboard-provider copy',
\ '*': 'clipboard-provider copy',
\ },
\ 'paste': {
\ '+': 'clipboard-provider paste',
\ '*': 'clipboard-provider paste',
\ },
\ }
endif
此時,重啟nvim,應該已經大功告成了。復制時,通過 "+y 命令復制,就可以復制到剪切板。如果不行,可以輸入 :reg ,看相關代碼是否插入到 + 寄存器中。如果在寄存器中,同時你的clipboard-provider 腳本沒問題的話,應該是可以成功復制的。
原始文章:
https://zhuanlan.zhihu.com/p/419472307
聲明:
文章轉載只為資料不丟失