Updated Vim Config

Published on

Tags: 2023 Software

TLDR: I made a lot of changes to my neovim setup. You can find them here

Intro

I’ve been using vim as my editor at home for a few years now. I’m comfortable with the motions, functions, and have started using vim modes in other programs because they’ve become ingrained in my muscle memory. It’s also really fun to use.

I didn’t use strictly vim at work until recently. I work as a typescript developer, and with the tooling our team uses, it made more sense to just use vscode like everyone else (I’ve actually been using vscodium, but same difference). I used a vim extension in it and customized a lot of the keybinds to what I would use in vim anyway, so I finally decided to pull the trigger and use vim exclusively.

This week I sat down and got neovim working pretty well and wanted to let you guys know about my setup a little bit.

I’ve written about vim before in one of my first ever blog posts which you can find here if you need convincing on why you should at least learn vim.

Neovim vs Vim

Vim is actually in a family of text editors that come from Vi created by Bill Joy in 1976. Vi and vim are modal text editors, which means that you utilize different modes to edit text. They’re primarily used in the command line, and are known for being light on system resources.

Vim (stands for Vi-Improved) was created to iron out some of the bugs seen with vi, and to add features. Neovim is doing the same thing to vim what vim did to vi. Neovim has slimmed down the code base, and now allows for lua as the configuration language along with VimL (the standard config language).

I use neovim, and this setup will NOT work with normal vim because most of it is written in lua. I currently use v0.9.0-dev, but I think this will work with v0.7+ maybe, you’d have to check if you want the exact same lsp setup.

My Setup

Most of my lua setup came from this tutorial and ThePrimeagen’s other videos. I’ll leave him to explain how to get started with a “vimrc” if you want to write your own, but I’ll go over certain parts that are more specific to my setup.

Some of my remaps and settings come from Luke Smith’s vimrc, like shortening <C-w><C-l> to move to the buffer on the right to just <C-l>, and adding spell check with <leader>o (o for orthography). He also uses nvim, but he uses the traditional VimL form of config files. His init.vim file is here.

Vim’s syntax highlighting by default is pretty good, it bases it on the file extension and applies it that way (if you have highlighting turned on). Sometimes though you want files read a certain way, or you want them to have specific settings. I normally have an indentation of 4 spaces and have vim convert the tabs to spaces, but for files that end with js/jsx/ts/tsx it uses 2 spaces instead.

With the workstation I’m using currently (me lying down on the couch), I don’t have a separate keyboard and mouse, so I use the one on the laptop and always end up pressing on the touch pad while I’m typing. This causes issues when typing because it ends up moving me somewhere totally different. So I just disabled mouse use entirely. I don’t use it in vim anyway, so it’s no big deal for me.

I have a few keybindings (that I don’t use that often actually) which call out to programs that should be on your path if you intend to use them. They come from Luke Smith’s scripts, and they have their own dependencies themselves.

If you read the lua/jacksontaylorxyz/remap.lua and after/plugin/which-key.lua files, you’ll probably notice I try to keep the binds simple and easy to remember. E.g. <leader>ff is (f)ind in (f)iles, <leader>bc is (b)uffer (c)lose, etc.

Plugins

I used to use Plug, but have switched to packer, just because it was used in the tutorial from before. You can find it here. I don’t have an opinion on plugin manager, but packer works pretty well, and is similar to Plug in syntax.

Quality of life things

* - tagbar uses your local ctags installation. ctags is a program that parses out the elements/tokens from your code and creates a file that has them all indexed so another program can parse them. tagbar just loads the current file into a buffer and lets you jump without having to create a file. The version of ctags you use does seem to matter. I use exuberant-ctags, and it does not have typescript support by default. You can add to the regex patterns that it uses, but it doesn’t really work that well. I’ve read universal-ctags does have typescript support, but haven’t tried it yet. I also don’t use this function very much anyway, so I’m not in too big of a rush to get it fixed.

Anything to do with git

I still commit and push mostly from the command line, because it’s just second nature. But adding this to my config shouldn’t be too hard. Right now I also still use vscodium to stage hunks when I want to break up commits. I’m not sure how easy that is to do, I don’t know the syntax of the git command for it on the command line, otherwise I could probably add it now.

Different vim modes

Vimwiki is a really nice way to keep documentation or keep notes on tickets and projects. It’s just markdown which isn’t very special, but Vimwiki gives you tools to jump to different files through the links and gives you tools to create tables nice features for editing. I’ve thought about trying to make a website with it because you can convert it to HTML. I don’t normally launch Vimwiki after I start vim though. I’ve got an alias on my machines called wiki that runs vim +VimwikiIndex which will open the index page.

Fancy stuff

* I use mostly lua for my configuration, but there is 1 file that would be time consuming to write in lua, and I don’t care to do it right away. I have a plugin for a startup screen if vim is called without an argument, and it has a bunch of ASCII art and quotes in these arrays and stuff. It basically takes an ASCII drawing and puts a random quote from a set of quotes. I may try to convert it to lua and have it read a file and use fortune, but for now it’s VimL. I think you can use the startup screen without these fancy ASCII art things, but I like them. Apart from that plugin, everything else is in lua.

** Which-key was mostly what I was fussing with to get my setup right. It’s not that hard to use and setup really, but I combined 2 different tutorials and that was getting messy. It’s basically a menu that pops up when you push your leader key, or a key that requires another one after it such as g or '. It just shows you what options you have. Right now my leader key is space, so for things like finding searching the entire project where I can push <space>ff and it will bring up a text input. But if I were to stop at just <leader>f it would show me all keybinds that start with that combo. You can also include descriptions for the keybind, or leave it as is and it’ll show you the command it’s gonna run.

Themes

Language supports

LSP

LSP is an area that I struggled getting right because it’s still relatively new for neovim, but lsp-zero made it really easy to use. LSP stands for Language-Server-Protocol, and is a way to get autocompletion and diagnostics while you’re writing code. Your editor calls out to a program (a language server) on your machine and it gives the editor instructions on what you’re trying to do.

My setup is still not perfect, but I am able to jump to definitions and get errors near real time (takes about 5 seconds to update on some larger files). I want to mess around with snippets as well for things like tests in typescript and common things I use at my job.

How to use my config?

I haven’t totally tried to install it anywhere else, but I think that if you clone the repo to ~/.config/nvim/ and run the install steps from packer’s github, and then run nvim +PackerSync it should work? I know it doesn’t play nice with windows, I’ve had some issues trying to get vimwiki installed as well as some other plugins. That’s dealing with installing a c compiler and node, which is kind of a pain that I have to have node installed to use my editor.

You can also just read it and pick out what you want. That’s easy too if you have a setup already.

Why not emacs?

Emacs is a well known “editor” (people meme about it being an operating system in a way). There are many pre-configured builds and versions of emacs like Doom and Spacemacs which include Evil-mode (vim keybinds) as well as many other tools and programs, so why not just use those? I’ve tried Doom, and it’s ok, and I might try it again eventually. The most basic answer that I can give as to why I don’t use it is that I don’t know lisp well enough to configure it how I want, and I didn’t really find the documentation all that user friendly for those who don’t know lisp. That’s fine, I don’t think that’s an issue, it’s just more work than what I feel like doing. If I wanted to relearn all my binds and use their defaults then I’m sure it’d be fine.

There’s also the debate over what all should be in an editor, because emacs is so large and so feature dense you don’t need much outside of it. I’m kind of in the camp that my editor should really only edit text (or do things that revolve around that), which my setup follows pretty closely. With emacs you can have a browser, an xmpp client, games (literally DOOM), discord, and so so much more. From a tinkerer’s perspective that’s pretty cool, don’t get me wrong, but I don’t need that much in my editor.

Conclusion

That’s pretty much it. I’m enjoying using nvim, and have more ideas on what can be done with my setup. So if you’re interested, you can clone my repo and keep up to date with it.

by Jackson Taylor