Falling in love with Vim again

Written on March 16, 2018

I’ve had a crush with Vim for a while now. It’s what I use to write all my posts to my site. Paired with Goyo, the writing environment is very minimal and allows me to focus on the words.

Aside from writing though, I dabbled in Vim from time to time to use it as my text editor for programming but always had trouble making the transition. For programming, Atom has been my go-to editor of choice for a long time. My inability to transition over to using Vim as my editor of choice for programming was just I had gotten comfortable with using Atom and hadn’t taken the time to learn how to use Vim in my workflow.

Over time, Atom started to feel a little much for what I need in a text editor. For one, it was always asking me to update. I could never resist when that little squirrel would pop up in my status bar indicating there was an update. Recently I also found myself setting up my developer environment repeatedly. Which meant every time I had to get Atom up and running the way I liked it, I would spend a good chunk of time redownloading plugins and updating settings.

While I’m sure there is a way to figure out a more automated approach to doing this that I could easily version in my dotfiles repo, I didn’t want to spend the time to do it.

After reading this article on one programmer’s journey into switching over to Vim, I decided to give it a shot as well. It made sense because I’ve always got the command line open and Vim is only a few key strokes away.

One of the biggest challenges for using Vim as a code editor was navigating files in a project and finding the right files. I’ve always used NERDTree to navigate and manipulate files in a project folder but could never figure out how to find instances of code across files in a project. This is something I do quite often in Atom and it is as easy as hitting command + shft + f and typing in the term that I’m looking for.

After doing some research, I’ve solved this issue by using a combination of grep and the FZF plugin — by the same author of my favorite writing plugin Goyo, Junegunn Choi.

By running grep -r 'String to search' . in the root of a project folder, you’ll get a result of all files where the instance of the string is matched on your screen. The -r is to tell grep to search recursively and the . is to indicate that the search should start in the current folder. The operation is super fast on the command line. There is also a Vim version of grep but I haven’t quite figured out how to use it yet.

Once I know the file I’m looking for, I switch back to Vim and run :FZF and type a few keywords that would allow me to select the file I’m looking for.

I also took stock of which plugins I was using. Since one of the benefits of using Vim is that you can store your settings versioned in a dotfile and have the same setup on a different machine.

I demoted NERDTree but didn’t remove it. I decided to instead give Vinegar a shot. Vinegar enhances netrw, which is Vim’s built in file browser. What that means is netrw is blazing fast. Tied with the - key used to both toggle netrw and move up a file tree, it makes project folder navigation a breeze.

I decided to keep NERDTree around because visually it allows for browsing the project folder a lot more elegant. Which means at a glance I can associate myself with a project structure a lot quicker. I also like NERDTree’s move function. It allows you to either move the file you’ve currently selected or do other things like copy or delete the file as well. I used the move function a lot to make copies of files. This is what I usually did first when I wanted to write a new entry in my Jekyll projects.

This is not ideal since I usually start a new entry by first deleting the content that was copied over and then updating the front matter. I’m finding the workflow that I’ve discovered in netrw to be faster.

The workflow starts out by first hitting the % key, which prompts me for the name of the new file. From there I’ll type in the file name and hit enter, loading the new file in the buffer. I then hit the = key which I’ve got mapped to open a new split. From there I’ll open up a previous post to yank it’s front matter and close the split and paste it into the new entry.

My Vim workflow still has room for improvement, but this week I fell in love with Vim again and this time see myself using it as my text editor of choice.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share articles like this one in your inbox. Sign up for my newsletter.