This explains how to set up Vim on Ubuntu 18.04 on Windows Subsystem for Linux 2 (WSL2) in order to share the clipboard between Windows and Ubuntu.
- Windows 10 Home
- Ubuntu 18.04 on Windows Subsystem for Linux 2 (WSL2)
- Build Vim with the clipboard option enabled
- Set up VcXsrv Windows X Server
- Connect VcXsrv from Ubuntu on WSL2
Install necessary dependencies to build Vim with the clipboard option enabled:
sudo apt install ncurses-dev libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev
N.B. Not all of them are required to build Vim with +clipboard, so skip installing unnecessary libraries if you want
Build Vim following the official guide:
cd /usr/local/src
sudo git clone https://github.com/vim/vim.git
cd vim/src
sudo make distclean # if you build Vim before
sudo make
sudo make install
Download and install VcXsrv Windows X Server, then run XLaunch with the following options:
- Multiple windows (default)
- Start no client (default)
- Extra settings
- Clipboard (default)
- Primary Selection (default)
- Native opengl (default)
- Disable access control
- Clipboard (default)
Basically, you just need to tick all of the extra options. Other than that, every setting is the default.
Click the [Save configuration] button and save the configuration in C:\Users\<USER NAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
in order to start VcXsrv when Windows starts.
Log in to Ubuntu on WSL2 and set the DISPLAY
environment variable:
LOCAL_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export DISPLAY=$LOCAL_IP:0
That's it! Enjoy your Vim life on Windows!
It worked well with neovim. I just skipped the first step and installed neovim with instructions from https://github.com/neovim/neovim/wiki/Installing-Neovim#linux, then followed steps 2 and 3 and 🎉