Last updated: 2024-12-31 Tue 16:01

Neovim installation on WSL2 Debian Sid under Windows 11

Table of Contents

1. Philosophy

I've been using Vim since ~2008, but Neovim has meanwhile gathered a very vibrant plugin community for writing, note taking and task management, which is my main Vim use case. These are my notes how to set up Neovim to support that.

2. Installation

Neovim is in Debian but its latest stable lags several major versions behind the upstream stable, so installing with bob.

Install dependencies for bob:

$ sudo aptitude install rustup

$ cd ~/sources

$ wget https://github.com/MordechaiHadad/bob/releases/download/v2.8.3/bob-linux-x86_64.zip

$ unzip bob-linux-x86_64.zip

$ cd bob-linux-x86_64/

$ chmod +x bob

$ ./bob use stable

Nvim is now installed. Check the release installed:

$ ./bob list
┌────────────────────┬─────────────┐
│  Version           │  Status     │
├────────────────────┼─────────────┤
│  v0.9.5            │  Used       │
└────────────────────┴─────────────┘

And what that release version consists of:

$ nvim -V1 -v

NVIM v0.9.5-dev-2947+ge1ca7a7bf
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Compilation: /usr/bin/gcc-10 -O2 -g -Og -g -flto=auto -fno-fat-lto-objects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wno-conversion -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always  -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -I/home/runner/work/neovim/neovim/.deps/usr/include/luajit-2.1 -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include -I/home/runner/work/neovim/neovim/build/cmake.config -I/home/runner/work/neovim/neovim/src -I/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth in nvim for more info.

:checkhealth will show warnings, but unless a certain config requires them as dependencies, warnings can be ignored.

Then keep your installation up-to-date:

$ ./bob update |nightly|stable|--all|

3. Post-installation tasks

3.1. DONE Symlink nvim

So that sudo nvim works with bob-installed nvim.

Otherwise $ sudo nvim gives:

sudo: nvim: command not found

$ sudo ln -s /home/pyyhttu/.local/share/bob/nvim-bin/nvim /usr/bin/nvim

3.2. DONE Install a sane config

Here's one to start with:

$ git clone https://github.com/meuter/nvim ~/.config/nvim

After this you have relatively understandable config under $XDG_CONFIG_HOME/nvim/lua you can start tweak further. I've modified it mostly to disable plugins I don't need, and ones I need under plugins/:

~/.config/nvim/lua$ tree
.
├── disabled
│   ├── aosp-vim-syntax.lua
│   ├── bufdelete.lua
│   ├── clangd_extensions.lua
│   ├── cmake-tools.lua
│   ├── crates.lua
│   ├── dap-ui.lua
│   ├── dap-virtual-text.lua
│   ├── diffview.lua
│   ├── dressing.lua
│   ├── gitsigns.lua
│   ├── indent-blankline.lua
│   ├── inlay-hints.lua
│   ├── lsp-config.lua
│   ├── lsp-format.lua
│   ├── lsp-zero.lua
│   ├── mason-lspconfig.lua
│   ├── mason.lua
│   ├── mason-nvim-dap.lua
│   ├── mason-tool-installer.lua
│   ├── neodev.lua
│   ├── nibbler.lua
│   ├── rust-tools.lua
│   ├── schemastore.lua
│   ├── toggleterm.lua
│   ├── trouble.lua
│   └── venv-selector.lua
├── plugins
│   ├── catppuccin.lua
│   ├── cmp.lua
│   ├── colorizer.lua
│   ├── lastplace.lua
│   ├── lualine.lua
│   ├── orgmode.lua
│   └── telescope.lua

Here's my ~/.config/nvim/init.lua.

First install folke/lazy.nvim as your plugin manager.

Then get the plugins and place them at ~/.config/nvim/lua/plugins/

3.3. DONE Install manual

In order to do $ man nvim:

As neovim binary was installed with bob, the manual isn't copied, so remember to copy the manual to its place:

$ sudo cp ~/.local/share/bob/v0.10.2/share/man/man1/nvim.1 /usr/local/share/man/man1/

3.4. DONE Install clipboard support

So that copying / pasting into / to nvim works under WSL2 works. There are two ways.

Install first xclip so that in :checkhealth clipboard support is satisfied (OK).

3.4.1. win32yank

Easiest way (tested) to do this is with Winget and win32yank.

Launch cmd.exe and issue:

winget install win32yank

Then restart Expolorer/computer for win -> win32yank is registered as an executable.

After this also mouse right click menu with its copy/paste works, as will "*y-yanking in visual selection.

See this reddit thread for more info.

[2024-12-31 Tue]: Copy to/from WSL neovim started to work after added to by init.lua also:

vim.g.cliboard = {
  name = 'OSC 52',
  copy = {
    ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
    ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
  },
  paste = {
    ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
    ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
  },
}p

3.5. DONE Install LuaRocks support for Lazy.nvim

Not strictly needed, but if I have plugins that need it.

3.5.1. On getting nvim-orgmode/orgmode to work

Syntax highlighting doesn't work until you have org grammar installed. Install with:

:lua require('orgmode.config'):reinstall_grammar()

3.6. Observations and future direction

3.7. DONE init.vim vs. init.lua

Both config files are not supported at the same time, but I can "nest" init.vim config into init.lua, so write config to init.lua with that option in mind.

Here's a helpful lua-guide to get started. There's also kickstart.nvim which goes through the config. Here's vhyrro's video on understanding Neovim.

3.8. NEXT Go through the old vimrc and migrate config to init.lua

3.9. Plugin and init.lua configurations by others

In case you want to search by plugins, or configurations, what others have set up their neovim, head to https://dotfyle.com/

3.10. Motions for editing

ca and ci are game-changing. E.g. ca[ (“change around [”) or ci( (“change inside (”). They even work when you’re currently inside or outside the bracket/parenthesis/quote/whatever on the same line.

3.11. Command-line usage

As mentioned here. Invoked with q: and by pressing <ctrl-f>.

Tuomas Pyyhtiä / CC BY-SA NVim 0.9.5 (nvim-orgmode 0.3.4)