25 August 2023

WSL2 - Working with Vim

Overview

This is a page that will be kept updated as I find solutions to the quirks of using Vim in WSL2

Copy and Paste

The first thing we miss, when using Vim in WSL2 is native copy and paste.

 "+y and "+p

Fortunately the fix is straight forward.

Download and install the following package from Github https://github.com/equalsraf/win32yank/releases

Then add the following to your Vim configuration, which I found at https://superuser.com/a/1557751

set clipboard+=unnamedplus
let g:clipboard = {
          \   'name': 'win32yank-wsl',
          \   'copy': {
          \      '+': 'win32yank.exe -i --crlf',
          \      '*': 'win32yank.exe -i --crlf',
          \    },
          \   'paste': {
          \      '+': 'win32yank.exe -o --lf',
          \      '*': 'win32yank.exe -o --lf',
          \   },
          \   'cache_enabled': 0,
          \ }

For this to work best we use Windows Terminal

Enable Visual Block Mode

When using Windows Terminal, we can’t use Visual Block mode.

To fix this, just remove Ctrl + V and Ctrl + C in settings.json so you have visual block mode

tags: wsl2 - vim