Vim - Part 1

Recently I've been going through some courses that are more configuration and command line-oriented, and that's gotten me back into using Vim, a terminal editor that I used regularly in the past but have neglected recently. I picked up Vim several years ago when I worked almost exclusively with Ruby on Rails. Vim has a strong following in the Ruby community for some reason–I think because the Thoughtbot company (which supports Rails) is a strong proponent of Vim.

I drifted away from Vim somewhat when when I started working more with Python. Visual Studio Code has excellent Python support with their Pylance language server, which doesn't work in Vim. Mostly I was just less familiar with Vim integrations for Python, and the Jupyter Notebook environment also factored into this switch.

However, these courses, along with getting back into tmux have let me to picking Vim back up, which also led me to discover that Microsoft has open-sourced Pyright, a language server that backs Pylance and provides many of the same features (like autocomplete, linting etc).

For reference tmux stands for "terminal multiplexer" which basically just means that you split your terminal into "panes" or split windows, like this:

tmux example

What you see here isn't stock Vim. It's using themes and a tmux config and several Vim plugins. And it's also not ground-breaking, VS code with a command-line editor can also do something like this.

I've thoroughly enjoyed getting back into Vim, and playing around Microsoft's server plugin. It adds slick and intuitive auto-complete and import support as well as jumping to definitions and such:

Vim Python Plugin

Props to Microsoft for making these language servers available to systems like Vim. What's great about a setup like this is that you can very much customize it, and use as much or as little of the tooling as you like. You can have all of your configuration in a dot file, version it with Git, and check it out on any computer that you use Vim on. Prior to VS Code, I would have said that you'd need a paid product like RubyMine or PyCharm to equal the functionality of Vim. VS Code changed that equation somewhat and, and when Pylance came out, it was hard to justify building and maintaining my Vim setup.

It may still be true that's it's hard to match features 1-for-1 with Pylance. However, I've found that, with Pyright and other linters and tooling, my Vim setup seems just as good as any editor. And there are certain things that I like better, such as tmux integration for navigating to the terminal from Vim, swapping, zooming, and un-zooming panels, and Git integration. When you add in search features like Ctrl+P (shown above to select the file) and ag.vim, there are times that it feels genuinely faster to navigate around.

BUT, with all of that said, I'm not sure I'd recommend anyone adopt Vim over an editor like VS Code, and I have absolutely nothing against paid tools. I'm also not even sure that I'm any faster than a proficient VS Code user, and that's after hours spent tweaking my .vimrc (Vim's config file), reading several Vim books, and watching many an online tutorial. My .vimrc file is massive and confusing and, after several years away, it took me a good while to figure out how to update it so that I can use it today with updated plugins. With VS Code and a couple of one-click plugin installs you could get most of the base functionality that I have.

I think a lot of what I wrote about "Lifehacking" applies to why I enjoy this setup. I have a lot of fun tweaking and optimizing things like editors. Also, Vim itself is just an amazing piece of technology. Although I'd been aware of Vim as a simple editor for a very long time I was blown away the first time I saw it set up as a full-blown editor. After struggling with complicated editors like Eclipse and Netbeans for Java development, where I'd have to dedicate a lot of system memory to get them to run correclty, I couldn't belive that a terminal program could basically do all of the same things, and with open source software.

If you haven't heard of Vim before, it might sound like something that's esoteric, and maybe meant more for system admins or hard-core Linux hackers. That's what I thought before I started using it for Ruby development. But in a 2019 Stack Overflow survey of development environments, Vim came in at 5th place. For a terminal editor that had its origins in 1987 that's just crazy to me.

I plan on doing a couple of follow-up posts to highlight some features and plugins that I really like for Vim (with some tmux features thrown in as well). Even if you don't plan on using Vim as your primary editor I do think it's useful for one-off edits in the command line. Maybe the most notorious feature of Vim is that it's a modal editor (by default keys don't edit but navigate). That intimidates a lot of people but it really shouldn't. With just a few "normal" mode commands you can easily move around and edit things and generally be productive. The more exotic commands are cool but definitly not something you need to learn right away (or ever if you don't want to).

Subscribe to Pithological

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe