LoginSignup
11
3

More than 3 years have passed since last update.

Arch Linux の neovim でクリップボードにヤンクした内容を保存できるようにする

Posted at

はじめに

Arch Linux を使い始めています。エディタは neovim を使っているのですが、neovim 上でヤンクした内容をクリップボードに保存できず困っていました。

解決方法を調べたので、こちらにまとめます。

tl;dr

以下で実現できました。

  • xclip をインストールする
  • neovim の設定で以下の設定をする
set clipboard+=unnamedplus

調べたこと詳細

詳細は neovim の help で確認できました。

:help clipboard

以下、ヘルプの内容を引用します。

 ==============================================================================
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)

ヘルプの内容を簡単に抜粋します。

  • neovim はシステムのクリップボードと直接連携していない
  • 代わりに、システムのクリップボードと透過的に連携するシェルコマンドを扱う provider と依存している
  • ヘルプに記載されているクリップボードツール(xclip, pbcopy,...)が存在していれば、暗黙的にレジスターに登録される

Mac などでは標準で pbcopy が導入されていたので、クリップボードを有効にする設定をすればすぐ使えていたのですが、Arch Linux ではまだクリップボードのツールをインストールしていなかったため、動作しなかったのかなと思います。

終わりに

マニュアル読んで学習するの大事ですねー。解決はしたのですが、まだ理解しきれてない部分も多いので、概念を改めて確認していきたいと思います。

参考

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3