I’m not someone who sets about the house with a duster and mop when spring arrives, but I am a fan of having a spring clean of my text editing setup. Let’s face it, if you’ve read this blog for any length of time, you know full well that I need no excuse whatsoever to tinker with my setup. I’ve long since come to terms with the fact that I will probably never settle for good on the One True Text Editor. For one thing, I think there probably isn’t such a thing: I use a text editor for many different tasks, and in each of those I have different priorities for my working environment. It is also the case that editors are being improved all the time, so it is worth occasionally trying out (or re-visiting) and editor to see if it fits your needs better than your current system. With that in mind, I got the editor-tinkering itch recently, so I thought I’d write about about the changes I’ve made.
My most recent serious editor exploration was of Spacemacs. I love Spacemacs and think it is a terrific project with lots of fantastic features. I used it for quite a while until I got to a busy patch and simultaneously had a persistent issue with org mode and a couple of other things. I didn’t have time to fix it, and so went back to using Sublime Text (which is also a fantastic text editor). After my workload subsided a bit, I wandered between different editors, but not really settling. A couple of weeks ago, I decided that I needed a total spring clean of my command line setup, to rationalise it a bit, as it had got cluttered up with layers of things that I had tried out then dropped, or which had become broken with updates of other elements of the system: in other words, dependency hell.
I decided to start with a more or less clean slate, and looked around for an easier way to maintain my configuration (dotfiles), that would allow me to sync them between the various machines I use. I ended up with dotdrop, which I have to say I like a lot. The idea is that you create a
*.yaml format config file to tell dotdrop how to link (or copy) your files into your home directory. You can optionally run shell commands (‘actions’) as you do so, which is handy for updating vim plugins after you have copied your vim config across. It made me think about the best way to organise my configuration files to make it easier to keep them up to date, so that was a bonus. I’m not quite there yet, but my aim is to set this system up so that I could bootstrap a full installation of my command line tools and configuration on a fresh system. I have started using
pyenv to manage my Python versions (with the help of specific requirements.txt files), and I am thinking about using a Homebrew
Brewfile to be able to easily reinstall all the tools I need.
zsh as my shell, along with the ubiquitous oh my zsh. I’m not sure that I really need all that configurability, since my use of the shell is fairly simple, but for now I’m sticking with it. I did clean out some of the plugins that I wasn’t using to make things a bit snappier. I also installed (properly this time) z which enables you to easily jump to directories you have previously visited, and fzf which is like Alfred or Launchbar for the command line. If you want to open a file or
cd to a directory (which isn’t yet recorded in z), you can start to type the command (e.g.
vim), then hit
Ctrl-t and a recursive list of files in your current directory pops up. This is filtered as you type in a ‘fuzzy’ fashion, so it’s easy to narrow it down to what you want. Once you hit enter, you are back on your command line, and you can complete your command. It is incredibly handy once you’ve got it set up, and makes navigating around deeply nested folders simple. Finally, in my wanderings through other people’s dotfiles, I came across the base16 framework for syntax highlighting themes. The themes themselves are very nicely done (I use base16-material for a dark theme and base16_one-light or base16_tomorrow for a light theme), but the base16-shell tool makes it even better. This allows you to skip having to set up themes in Terminal or iTerm2, and instead change them on the fly with a command at the command line. Better still, it carries through beautifully to vim/neovim if you use the terminal versions of those editors. I mostly use a dark theme, but sometimes my eyes feel like they need a light background. Previously, I used to avoid switching themes in the terminal, because it never seemed to work cleanly. Now it is very slick, and I switch whenever I need to.
I’ve used vim for a long time, but again, my configuration had got messy and encrusted with broken things over time. In the meantime, the neovim project had made rapid progress, modernising the code base of vim and fixing some of the more annoying issues. Since I was in spring clean mode, I decided to start with a blank configuration, and build it up bit by bit, aiming for the smallest number of plugins that would make me feel comfortable in my editor.
Neovim is fantastic. The terminal version is working brilliantly, and I love the fact that I might one day be able to use my fully customised version of neovim embedded in a fully-loaded GUI IDE. That seems like the best of both worlds to me, but in the meantime, I have a very comfortable, usable system. I love the integrated terminal (I have no need to use tmux now), and the fact that neovim can run processes asynchronously makes everything very snappy. You can now write plugins in Python (actually, in more or less any language), which makes it significantly easier for me to customise it myself. My
.vimrc (or now, my
~/.config/nvim/init.vim) is relatively slim, as I am trying to use in built-in features supplemented by small amounts of customisation wherever I can. However, I have come across some brilliant plugins that I wanted to mention.
I had never really got to grips with session management in vim before. This made it slightly awkward when I wanted to go beyond a quick edit of a single file, and work in a project folder. If I had to quit vim while in the middle of working, and pick up again later, I had to open all my windows and set them up which was annoying. I think that my problem was that I didn’t really understand how sessions worked in vim. Partly as a result of reading Drew Neil’s excellent Modern Vim book (which I highly recommend if you are thinking of using neovim), I understand it much better now. I also found the startify plugin which leverages sessions in precisely the way I want to use them. Once you have your environment set up the way you want it for a particular project, you can save a named session in a
sessions folder alongside your neovim configuration files. You can then load these from the startify start screen when you start neovim, or switch between projects once you are working in neovim. It’s very configurable, so you can set it to autosave your session before you quit neovim or switch to a new project. All the useful bits of your working state get saved, from the buffers you have open to the window arrangement. It also sets the working directory to the root of the project directory, which also makes it easier to use tools like fzf (which I use in neovim too) to navigate the project. Basically, this plugin alone removed 90% of the friction I used to encounter when using vim in the terminal. I love it.
Another plugin I came across that I use all the time is Scratch.vim. This opens a temporary scratch buffer for you to write quick working notes, or paste random things for later use. I love the way that it is so quick and unobtrusive to use: you just hit
gs in normal mode, and a split window opens up in insert mode. You can configure it so that as soon as you go to normal mode, the window closes, and you go back where you were before it opened. I’ve been using it for quick notes I made on what I want to cover in this article, and I can just pop it open, take a look and close it without losing my place.
I’m really happy with the way I’ve got things set up now. It feels like a powerful, but sleek and well-tuned, system. I keep my
dotbot directory version controlled with git, so it is very easy to sync up any changes I make to all my computers. I also like the fact that I built it up from scratch, so each plugin has earned its place, and I know what all the bits do. As I said earlier, I loved Spacemacs, but it is a very complex, layered system. If something goes wrong, it can be very hard to figure out how to fix it, particularly if some package has been updated and broken a few other dependencies. I will probably still use Sublime Text occasionally when I’m dealing with a more complex editing task, when something closer to an IDE is called for. But for everything else, I’ll be using neovim in a terminal.