My neovim setup two years later
About two years ago, I wrote these words about using neovim:
I can feel my stress levels rise as I try to remember how to do something simple like delete a letter. Using it feels unnecessarily complicated, and it is frustrating to have to do things so much slower than I am used to.
Over the last week, I have felt the opposite. Searching through a codebase is a piece of cake. Switching between commits to find the one that introduced a bug was really smooth. What once felt cumbersome now feels natural. What is surprising is that the secret was never a single magic plugin, rather it was sticking with the process. If you switch to the latest and greatest every week, you never give yourself a chance to explore what you already have.
If I could go back in time, here are the things I wish I knew:
A lot of plugins rely on recent versions of neovim
Installing the latest version of neovim is as easy as the following four lines (substitute the x86_64 with arm64 if you are using a machine with apple silicon):
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz
sudo rm -rf /opt/nvim
sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz
Then adding the following to either .profile or .zshrc
export PATH="$PATH:/opt/nvim-linux-x86_64/bin"
I often run the latest stable version of Neovim, it is the few tools I manage outside of apt (even on Trixie, which has Neovim version 0.10.4-8)
File trees aren’t all they are cracked up to be
It can be nice to see all the files and their directories in a single place, however, it is slow to navigate to a file that way. Instead, the more efficient way to get to where you want to do is to either search through grep or for the filename. Telescope is the best tool for this. It can also navigate to files recently edited, which can make switching back and forth between two or three files really fluid.
Tmux is the way to go for window and terminal management
When starting out, many people like to use terminal plugins in Neovim like ToggleTerm. Tmux seems too fancy, and to be fair it adds to the learning curve. Yet, Neovim and Tmux go together really nicely. When coding, I usually have three panes open, my wiki to take freeform notes, neovim, and then a shell. If I need to open an additional shell quickly to do something like startup a docker container, then I’ll open a vertical or horizontal split from Neovim, but most times it is preferable to have the separation.
The big changes I made were the Tmux prefix to Ctrl + Space and switching between panes with Shift + Arrow Key. Next, you’ll want to use the tmux.nvim plugin so that you can navigate between tmux windows with Ctrl + h, j, k, l, and copy and paste between the two seamlessly.
Mason will allow you to grab formatters or LSP’s for each project
Globally installing things can create a real hassle if different projects use different versions or configurations. mason.nvim took a long time to wrap my head around. It isn’t really that fancy. It is just fancy way to install the following five components: Language Server Protocols (LSP), Debug Adapter Protocols (DAP), Linters, and Formatters. Instead of say, installing the prettier plugin in vs code, just open up mason with :Mason, select prettier for the formatter list, and press i to install.
Be careful of bloat
With so many plugins out there, it can be tempting to just keep adding and adding. If you look at your list of plugins and cannot remember what each one does, then perhaps it isn’t actually serving an essential purpose. Learning to really harness the power of four or five good plugins will always be better than knowing a bit about 100. Focus on the basics, you need to first find code, edit it, test it, then commit it.
I haven’t gone over how to install everything here, but I am planning on writing a better README in my dotfiles repo if you are interested in the finer details.