Copy/Paste for Neovim in WSL
If you want a seamless copy/paste experience on Neovim in WSL there is a newly
recommended method for doing so, without having to install extra software.
Paste the following Lua snippet in your configuration and "+y
to yank
the selected text into your global register. Similarly, use "+p
to paste.
if vim.fn.has "wsl" == 1 then
vim.g.clipboard = {
name = "WslClipboard",
copy = {
["+"] = "clip.exe",
["*"] = "clip.exe",
},
paste = {
["+"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
["*"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
},
cache_enabled = 0,
}
end
Faster key repeat on Windows
With WSL, Windows can be a great developer experience. The one thing which
I did find lacking, especially when moving around in Vim, is that the maxixmum
key repeat rate in the configuration panel is too slow.
I was able to fix that with the following settings in Regedit:
[HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
"AutoRepeatDelay"="240"
"AutoRepeatRate"="12"
"DelayBeforeAcceptance"="0"
"Flags"="59"
"BounceTime"="0"
You have to login and out again for it to take effect.
Latest Neovim on Ubuntu
I’m using Ubuntu for my development environment, and Ubuntu does not have the
latest Neovim in their repository.
That’s why I choose to install the last version by source. The steps I take
are:
wget https://github.com/neovim/neovim/releases/download/v0.9.1/nvim-linux64.tar.gz
tar xfz nvim-linux64.tar.gz
sudo mv nvim-linux64 /opt/nvim
Now you have to make sure that /opt/nvim/bin
is part of your path. If you are
smart, and using the Fish shell, add this to your Fish config.
fish_add_path -aP /opt/nvim/bin
If you are on Bash:
export PATH=/opt/nvim/bin:$PATH
Enjoy your latest version of Neovim!
Emacs on Windows WSL2
So, it turns out that WSL2 is actually kind of neat, where it
runs a Linux image at almost native speed, and also supports
Wayland.
So, what’s the first thing you do in WSL2? Install Emacs of course!
Below is the script I use to install Emacs on an Ubuntu image.
To know what the latest stable version on master is, I look at this Github issue from Jim Myhrberg, who keeps track of those.
# Checkout Emacs
$ git clone git://git.sv.gnu.org/emacs.git
# Checkout latest stable version, see note above.
$ git checkout 8febda4
# Vanilla Emacs requirements
$ sudo apt install build-essential autoconf libgtk-3-dev libgnutls28-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev librsvg2-dev libxpm-dev libncurses-dev texinfo adwaita-icon-theme-full
# Native compilation requirements
$ sudo apt install libgccjit-11-dev
# Required for Native JSON
$ sudo apt install libjansson4 libjansson-dev
# Required for tree-sitter support
$ sudo apt install libtree-sitter-dev
$ cd emacs
$ export CC=/usr/bin/gcc-11 CXX=/usr/bin/gcc-11
$ ./autogen.sh
$ ./configure --with-pgtk --with-native-compilation --with-tree-sitter --with-json --without-pop
$ make -j$(nproc)
$ sudo make install
And, sometimes when you update the repository, it refuses to build. I usually fix that with running make bootstrap
er make distclean
.
Syncthing on WSL2
I like to use Syncthing to sync files between accounts and machines, and now even between my Windows subsystem and Windows itself.
To run Syncthing on WSL I use this script:
#!/usr/bin/env bash
SERVICE="syncthing"
USER="petar"
PORT=2103
OPTS="
--no-browser
--home=/home/$USER/.config/syncthing
--gui-address=http://127.0.0.1:$PORT
--logfile=/home/$USER/.config/syncthing/syncthing.log
"
if ! pgrep -x "$SERVICE" >/dev/null
then
daemonize /usr/bin/syncthing serve "$OPTS"
fi
Make sure to change your username and to make the port unique, if you run multiple Syncthings on your machine.