How to Migrate from Neovim to VSCode
Some tips on how to eaily move to VSCode as a Neovim user (sorry Primeagen)
Okay, okay. I know. Before you come at me with virtual torches and pitchforks, hear this first: I love Neovim. I’ve been using it non-stop for the past two years, and honestly, I struggled to use any other kind of editor. I loved the speed, the tinkering, the ricing, etc. It’s an incredible piece of open-source software and has a special place in my heart.
The truth: use whatever tool fits you best. The harder truth: be willing to try the other tools.
Several developers have switched from Neovim to VSCode, notably Nexxel and Melkey. Both of their pieces of content resonated with me on several levels, so I thought, “Why not try it for a week?” The worst case scenario was that I would hate it and move back to Neovim. However, it turned out to be harder than I expected. The first few days were rough; nothing was smooth, everything felt clunky, it was just awful. Of course, I already had the Vim keybindings extension installed, which helped, but something was still missing. After digging into it, I realized there were two things throwing me off:
- The clunky UI
- Vim mode specific keybindings
Let me go into more detail about how I resolved these problems, and hopefully it will help anyone who finds themselves in the same situation.
UI
In Neovim, everything is stripped down to the core editor. By default, there are no extra plugins, no file tree, not even syntax highlighting. Of course, this is by design, and, like Linux, you have to make a lot of decisions as to what you want your editor to look like and how you want it to behave. In my opinion this is a good thing, and it’s better to start out with less and slowly build more on top. Having just the minimal editor experience is a key UI component for the regular Neovim user.
VSCode is the exact opposite. There’s loads of extra stuff all around the editor that’s pure distraction. I mean, be real, who is using the minimap thing? What about that extra bar on the right with a bunch of icons that you’ll never use? It’s so aggressive that I wanted to get out as soon as I opened it. However, there are solutions to this! You can simply go to the View menu, then Appearance, and from there toggle all those nasty bits off. Now you can get VSCode looking more like this:
Keybindings
Altering the UI a bit is easy and takes a few minutes, but the keybindings were a whole other mess. Throughout my years of using Neovim, I had collected so many custom keymaps for different things that were unique to Neovim. I realized pretty quickly that I had no idea how I could use them again because they were bound to Vim modes. How do I use Shift + H
to switch to the previous buffer or Shift + L
to go to the next? How can I map that in VSCode? Thankfully, VSCodeVim has that covered, although it’s not the most intuitive.
If you visit the VSCodeVim docs, you can see they have some example configurations to remap keybindings for specific modes. For instance, I was able to add my lovely buffer switching remapping in normal mode with ease.
"vim.normalModeKeyBindings": [
// switch buffers with ctrl and left and right
{ "before": ["<S-h>"], "commands": [":bprevious"]},
{ "before": ["<S-l>"], "commands": [":bnext"]},
]
“Before” is simply the keys you’re pressing and either “after” or “commands” (if you want to do :enter commands
) will be the output of that binding. What I had a lot of trouble doing was going beyond the simpler stuff. Another one I loved using was Ctrl + H, J, K, L
to switch between panes in the editor. Because VSCode isn’t really using the same window API that Neovim has, those go out the window. How are you supposed to do those?
Here’s the sauce: discovering VSCode’s API. Something I had never done before is going to the built-in keybindings menu for VSCode and looking at what was in there. There’s so much there and it’s a bit overwhelming, but once you figure out how to find the command you’re looking for, it makes just about anything possible. For my pane switching keymap, I wanted to find which command was changing the focus. I searched “focus left” in the VSCode keybindings and sure enough, there it was: workbench.action.focusLeftGroup
.
Now back in our VSCodeVim config, we can add that method to the binding like so.
"vim.normalModeKeyBindings": [
//... other bindings
// better pane navigation
{ "before": ["<C-h>"], "commands": ["workbench.action.focusLeftGroup"]},
{ "before": ["<C-j>"], "commands": ["workbench.action.focusBelowGroup"]},
{ "before": ["<C-k>"], "commands": ["workbench.action.focusAboveGroup"]},
{ "before": ["<C-l>"], "commands": ["workbench.action.focusRightGroup"]},
],
It works like a charm. If you’re doing this yourself, something I found useful is right-clicking on the command in the VSCode keybindings menu to see the method. Another example where this came in handy was using the “Find Files” command. By default, it’s Cmd + P
on Mac, but I was used to something like <leader> + F
. When I searched “Open File…” in the keybindings, it didn’t show the method like the others did. However, after right-clicking, you can click “Copy Command ID” to grab it.
Configuring VSCode is not the most pleasant experience, but on the plus side you can save your config file and move it wherever you want, and you don’t have to mess with configuring as many plugins with Neovim. I’m still on the fence as to whether I’ll keep trying to use VSCode or go back to Neovim, but hopefully these tips help anyone out there trying to make it work for their own personal reasons.