Neovim with WSL

I finally took the plunge into converting to Neovim as my IDE earlier this year. As a linux admin, I can get around in vim and actually have always preferred it over the other command line options. Even having used it for many years, I admit I wasn’t aware of what it’s capable of until a few years ago after I started following theprimeagen.

There were times over the years that I thought about whether an IDE like Neovim in a shell environment would feel as efficient as it does doing system admininstration tasks. There’s just something about doing things in that environment with those tools that feels way more efficient. But as productive as things feel to me on the command line, there is this part of me that gets annoyed with some TUI apps that send you down the manpage portal to hell or have bizarre key commands. So I had my doubts whether I could stick it out without going back to the old pair of shoes, or moving on with the search for a new IDE not named Vim. (Zed has been on the radar since dropping a linux release, but after going to their website I’ll have to wait until my eyes stop bleeding.)

When I started switching to Vim from VSCode, I was doing it on my linux laptop exclusively. I was loving it and I wanted a solution for when I’m on my desktop - the hurdle being that I have one Microsoft oriented job and another that’s not - so I’m always towing this line where I’m doing all the Microsofty things and jumping around in terminals doing open sourcy things. That’s not going to change, so despite my desire to daily drive Pop!_OS or Debian on my desktop, it doesn’t suit my needs right now. I could have gone the cloud dev environment route, but that introduces some other issues I’m not interested in dealing with. This lead me to consider WSL.

Part of me thought there would be some gotcha that would annoy me or make it a clunky experience, but it hasn’t happened yet. It fits my needs and is very performant when compared to a full VM. I’m able to snapshot and compress it and stuff it in a folder with a couple lines of powershell and a scheduled task. I really wanted to keep it minimal. Its only job is to be a development environment, so I ended up choosing Alpine as the distro. Working with Docker quite a bit, I’ve come to really enjoy Alpine and it’s package manager. Once I was up and running with all the vim things, I was ready to see what all the hype was about…

Now, I haven’t been tinkering long enough with Neovim as an IDE to form an unwavering bias for it, but as Lloyd Christmas famously said:

“I’m getting that old fashion romantic feeling.”

dumb and dumber

What a breath of fresh air, honestly. The speed and responsiveness just feels good! Even things that you just know will lag and make you mistype and rage - are fast. Things like searching a massive codebase or scanning through a list of thousands of file changes. And that start-up time? Glorious! It was an extension of that productive feel I get working from the shell. Is it painful to really start using hkjl and remembering all the key binds just to do things you already know how to do with a mouse and arrow keys? Sure. I felt like a total idiot for a week. Mentally punishing myself for reaching away from home row. But I will say this, the payoff is well worth it. I never gave much thought about how our concentration waivers when we change our physical inputs. Removing that constant interruption creates a more intense focus on the code and the task.

I started with Packer before finding out it’s no longer maintained, so I switched to Lazy. It did take some time to refactor things. The way the pieces fit together - or the way I have them put together with my configuration - is prone to some dependency or order of operations pain when moving the config around to different machines. It will likely take me a bit of time to put together a nice package that I can deploy to any machine and be up and running quickly, but that’s for another day. Once I had the core things in place I was focused more on what plugins worked for me.

Telescope is great for flying around in projects. It’s super fast and the preview pane is so nice. I found myself using oil to navigate my project files the most, especially smaller projects without a lot of nesting. Oil’s buffer style file management is genius because if you know the bare minimum to get around in vim you can manage your files without needing yet more binds or memorizing anything. If you’re using netrw, give oil a try!

Did you know? Windows Subsystem for Linux (WSL) implements 9P as a server with the Windows host OS acting as a client using AF_UNIX sockets to make files available across filesystems. 9P (or the Plan 9 Filesystem Protocol or Styx) is a network protocol developed by Bell Labs in 1992. sauce

I didn’t really have many problems getting things to work right with WSL. I guess I don’t really know what kind of problems I expected to run into, but whatever skepticism I had was quickly replaced with pure nerd joy. I had no more issues getting Vim set up on WSL than I did on my laptop running Pop!_OS aside from having to install a few extra packages. I have no desire to launch any linux desktop apps, so maybe that’s a situation where WSL falls short. I also barely use the cross filesystem integration. I mostly work out of the WSL instance and push and pull stuff from there, but for anyone running an application that accesses the linux filesystem from the Windows environment I have no idea how that would perform. For simple file operations it works just fine.

A pleasant surprise was the Docker Desktop integration with WSL. If you’re using Docker Desktop in Windows you don’t have to install Docker in your WSL distribution, you can just make it available via Docker Desktop settings. This is really convenient if you’re already doing Docker stuff in Windows.

wsl docker

It looks like this works by creating a context:

docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                             KUBERNETES ENDPOINT   ORCHESTRATOR
default *           moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
desktop-linux       moby                Docker Desktop                            npipe:////./pipe/dockerDesktopLinuxEngine

Pretty cool. But, there is an issue that I ran into with memory usage when I first started using WSL. After a day or two I noticed a little bit of random lag, so I looked at task manager and the vmmem process was using close to 8gb of RAM. That seemed pretty excessive for what I was doing and the fact that I chose Alpine. I dug up the advanced settings for WSL and I made a .wslconfig file in my Windows profile with the following lines:

[wsl2]
memory=6GB
[experimental]
autoMemoryReclaim=gradual

autoMemoryReclaim is an experimental option, but it’s exactly what I want: Automatically releases cached memory after detecting idle CPU usage. Set to gradual for slow release, and dropcache for instant release of cached memory, and I’ve seen no negative impacts so far. I would have thought this was the default behavior, but anyways my vmmem RAM usage is now usually around 1.5-3gb. At this point I’ve had no other issues with WSL. I spend a ton of time working in it and it’s been smooth sailing. I’m genuinely stoked about it!

If you’re on the fence about whether to completely flip your world upside down and abandon Windows for Linux, give WSL a try and see how it goes. For the right situations it’s really the best of both worlds.

Copyright 2024. All rights reserved.

Built with Hugo and Bulma.