daniebker

Getting doom emacs style keybindings in vscode

· [Daniel Baker]

I switched back to Visual Studio Code as my primary code editor. There was too much going on with Emacs, and not being able to understand Elisp code that well, I often found myself copy-pasting snippets in the hope of getting something to work. In the end, the breadth and depth of configuration in Emacs were too far gone for me to build a useful editor out of it.

Figure 1: My ‘doom’ vscode

Figure 1: My ‘doom’ vscode

The two things that ultimately brought me back to VSCode were the refactoring shortcuts, which I could never get to work well in Emacs, and Copilot. I know there’s an unofficial port of Copilot for Emacs, but I prefer to stay on the official side of things.

However, there was, and still is, a lot I like about Emacs. Navigating with a keyboard is a breeze, and using VIM keybindings to get around a codebase is so much faster than reaching for the mouse. As a result, if I was going to go back to VSCode, I wanted to have a similar experience. At first, I was fine with memorizing a bunch of new bindings, most of which I remembered from previously using VSCode. However, they tend to be in awkward locations, like F12 to go to definition. I don’t want my fingers to travel that far! That’s when I stumbled across this blog post that gave some hints as to how to set up VSCode as a keyboard-centric editor.

Essentially it came down to installing these plugins, and I was able to get pretty much all the niceties of Emacs but in VSCode:

Vim brings in the NORMAL and INSERT modes, allowing both navigation and input with the keyboard. It also brings with it some keybindings, such as “d i " for deleting all text between " – something I use often.

GitWorktrees allows me to easily open up different worktrees in new editors from the keyboard. In Emacs, I’d do this through Magit, but the VSCode edamagit extension doesn’t offer the functionality to visit a forwtree.

VSpaceCode adds the leader key combination macros that I had in Doom-Emacs. I believe these originally came from Spacemacs, but if you haven’t tried them, they’re great. So far, I’ve only mapped some of the most frequent bindings, but as I try new ones, I take the time to add them to my settings.json.

WhichKey is a dependency of VSpaceCode. I haven’t looked into which functionality it brings in.

edamagit adds Magit functionality to VSCode. It’s much nicer to navigate commit changes and pushes through the keyboard, and I find myself taking more time to inspect my changes. It also lets you revert single lines in a hunk, which is unbelievably helpful.

Finally, the Dracula Official theme. I use this everywhere, and life wouldn’t be the same without it.

With these extensions, I was able to copy much of the keyboard shortcuts I was used to from Doom-Emacs. I made a few UI changes to get a similar buffer experience. Based on this blog post, I removed “tabs” and mapped the command ID to show active editors (“workbench.editor.showTabs”), think Emacs buffers, to the key combination “SPC ,”. Now, all the muscle memory I have built up from Emacs is still useful in VSCode. And, as I come across bindings I forgot, I add them to the settings.json (I even mapped opening that to “SPC f p”).

I’ve added my vscode keybindings to my dotfiles in github. I haven’t covered every binding since my plan is to add them as I come astart using them and adding in the ones that are missing I’d greatly appreciate a pull request!

In conclusion, I found that switching back to Visual Studio Code as my primary code editor was a good choice for me. Although I enjoyed some aspects of Emacs, such as navigating with a keyboard and using VIM keybindings, the depth and breadth of configuration required to build a useful editor was too overwhelming. With the help of some plugins, I was able to set up VSCode as a keyboard-centric editor that mimics many of the niceties of Emacs. Overall, I’m happy with my decision and plan to continue exploring and adding new keybindings to my settings.json as I come across them. If you’re considering making the switch, I recommend giving VSpaceCode and WhichKey a try and customizing it to fit your workflow.