I have "WSL Debian" installed and I installed a neovim
package inside. PAckage installs a nvim
text editor without a clipboard support. I can verify this like this:
$ nvim --version
NVIM 0.1.7
Build type: None
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-HEl3mV/neovim-0.1.7=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/build/neovim-HEl3mV/neovim-0.1.7/build/config -I/build/neovim-HEl3mV/neovim-0.1.7/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim-HEl3mV/neovim-0.1.7/build/src/nvim/auto -I/build/neovim-HEl3mV/neovim-0.1.7/build/include
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Optional features included (+) or not (-): +acl +iconv +jemalloc +tui
For differences from Vim, see :help vim-differences
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Note that under Optional features included
there is no +clipboard
entry and this means that my nvim
doesn't support clipboard out of the box.
Then I open the nvim
editor and execute a command :CheckHealth
to get this feedback:
## Clipboard
- WARNING: No clipboard tool found. Using the system clipboard won't work.
- SUGGESTIONS:
- See |clipboard|
This tells me (a) that clipboard is not working currently and (b) to use a command :help clipboard
inside the nvim
to get more info. So I execute this command and I can read this:
Clipboard access is implicitly enabled if any of the following clipboard tools
are found in your `$PATH`.
- xclip
- xsel (newer alternative to xclip)
- pbcopy/pbpaste (Mac OS X)
- lemonade (for SSH) https://github.com/pocke/lemonade
- doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
The presence of a suitable clipboard tool implicitly enables the '+' and '*'
registers.
If you want to ALWAYS use the clipboard for ALL operations (as opposed
to interacting with the '+' and/or '*' registers explicitly), set the
following option:
set clipboard+=unnamedplus
This tells me that even though clipboard support was not compiled in, it is still possible to implicitly enable it if we only install e.g. xsel
. So I do it:
$ sudo apt install xsel
This also tells me to put the below line in my ~/.config/nvim/init.vim
:
$ set clipboard+=unnamedplus
It looks like this should already be solved, but at this point things will not yet work. Why is that? This is because xsel
(as it's name implies) is a graphical application that needs X server in order to run!
So we install X server for Windows! One option is to simply install "VcXSrv"(link). This will create a "Xlaunch" launcher in the Windows start menu. We run this launcher and just click next until the "Extra settings" window. Here we make sure to check all the boxes like shown below and click "Next".

Now we will store our "Xlaunch" configuration by pressing "Save Configuration" and make sure to store our configuration as:
C:\Users\<Username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\config.xlaunch
This will make sure that X server will start with the same configuration whenever Windows starts! Note that X server has to be running before starting the "WSL Debian".
Now we click "Finish" and for this session X server will run.
Now inside the "WSL Debian" we only have to export a DISPLAY
enviromental variable which is where X server applications e.g xset
will search for a working X server session. Our job is to point them to our Windows machine! So we can export DISPLAY
like this:
LOCAL_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export DISPLAY=$LOCAL_IP:0
If you want you can add these two lines in the ~/.bashrc
file on "WSL Debian" so that they will always be exported when you open an interactive terminal.
Now everything should work.