Last updated: 2024-11-10 Sun 12:39

Neovim installation on WSL2 Debian Sid under Windows 11

Table of Contents

1. Neovim

1.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.

1.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|

1.3. Post-installation tasks

1.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

1.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

1.3.3. DONE Install clipboard support

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

  1. win32yank

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

    Launch cmd.exe and issue:

    winget install win32yank

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

  2. xclip

    Another way (not tested) is to install xclip and then put this into your init.lua:

    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
    

    See this reddit thread for more info.

1.4. Observations and future direction

1.4.1. 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.

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

1.4.3. 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/

1.4.4. 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.

1.4.5. 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)