For some stupid reason, I decided to start using a programmer’s best friend, vim, as my main text editor. This isn’t the first time I’ve tried; twice before I’ve been unsuccessful. But this time it’s different. I have a fun, new keyboard that I want to use as much as possible during the day.
How I changed from writing in GUI to writing only on the command line.
What I’ve learned is that this not for the faint of heart. At all. So many tiny little bugs. So many settings and options that have to be exactly right. So much crap to deal with, but man having the full power of vim at my fingertips feels great
For those unfamiliar with vim
Here’s a little test. If your on a Mac, open the application Terminal. Now once that’s loaded, type in the command
vi hello.txt. Once the screen changes and vim is open, try typing “Hello world”. It’ll probably look something like:
That’s because vim is a “modal” editor. The default, normal mode is designed to navigate a text document. When you hit
i in normal mode, it changes to insert mode. There are multiple ways to switch modes. In my example above, you used the
o command to open a new line below your current working line, and then entered insert mode. It is wonky at first. No application on the market today does exactly like what vim does. Most times, text programs use a basic GUI to navigate your text. Or, if you’re lucky, you get basic text manuvering with things like
⌘+RIGHT to go to the beginning of the line. Vim is expressive in how you can control it. The way I move around a document is probably vastly different than what another user might do.
Don’t feel like you have to learn vim. I find it more productive, but it is a tool that takes a long time to master. I’d only put my experience level at intermediate. I only wish to be as efficient as a master.
How to Whip vim into writing shape
When I initially started writing this piece, I had thought that I was using vim to its full potential as a writer. I don’t think I could’ve been more wrong. Currently, my vim setup, heck my writing setup, looks nothing like it did a few weeks ago. I’ve incorporated a lot of new applications into my workflow, but it still centers around being productive in vim.
The Command Line, But Specifically tmux
The first time I really thought to give vim a try was when I heard the podcast Technical Dificulties and their episode about vim. Sure, friends have said that it was the right way to edit text, but I really needed to hear an in-depth discussion about vim and its potentials. This fascination didn’t last long.
It wasn’t until I discovered the website Vim Awesome that I truly gave a vim a full go with a robust set of plugins. I understand a lot of true vim people would say that I’ve done this backwards. And they’d be right. Too many plugins and tweaks at the start doesn’t let vim truly shine. However, I had been using Vintageous inside of Sublime Text for quite some time and had gotten used to the basic movements and principles of vim.
My infatuation with the text editor was then accelerated with my discovery of tmux. While I’d heard of a terminal multiplexer before, I had no clue what it did. I really wish that I had done some digging earlier on.
Basically, a terminal multiplexer lets you have a bunch of terminals open that are aware of the existence of the others. While terminal applications, like the lovely iTerm, have most of these features right out of the box, it feels good knowing that I can control everything within the terminal itself. Certain keyboard shortcuts and dynamics within tmux make a ton of sense and seem to be sane defaults [^Except for
CTRL+B. That is a dumb keyboard shortcut]. I don’t know why tmux has stuck and the features built into iTerm haven’t. I have a feeling that only having keyboard navigation within tmux enticed me to actually start learning the app instead of lazily using mostly the mouse and sometimes keyboard shortcuts.
After customizing yet another whole app, I found myself in an editing environment where I was quick and precise. No longer holding down backspace, I could move about my documents like a madman. This made me happy.
It basically comes down to a few plugins and some changes to default behaviors to make vim an extremely powerful writing environment.
Most of what I do can broken down like:
- Find or create a file that I need write in
- Write in that file
- Open it in a previewing application
- Share the text in my file
I work on many tasks throughout my day. Having the ability to bookmark directories allows me to move about known folders quickly without having to rely on search. It is a crude system that allows me to navigate easily through multiple projects.
Once I’m in my desired directory, I use a two tools to find what I’m looking for. The first [NERDTree][nerd-tree] is a community favorite. It’s basically gives you a file finder inside of vim. It’s handy, but a little slow. The other is a fuzzy finder called [FZF][fzf], which I’ve just recently started using. Whilst I was using [CtrlP][ctrl-p], for quite some time, FZF seems to be fitting my needs much better. Not only is FZF blazing fast, it is technically outside of vim, so I can fuzzy find files anywhere that I am in my computer. I quite like that. Fuzzy finding is fantastic if you’ve never used it. I highly recommend you finding something in your dev environment, you won’t want to go back to regular searching.
A few cool benefits that FZF provides are the ability to search open file names or entire files quite quickly. Anything you can think to search, FZF has you covered. One especially neat trick I’ve found is combining FZF with The Silver Searcher. Speed of this search combo makes old problems of finding a single line of text in a perculiar file trivial now. I don’t know why most GUI apps can’t search quicly like the command line can.
Once I’ve found what I need to work on, I enter insert mode and start going. My plain text is exclusively Markdown so I’ve set vim up to handle this file type nicely. By hitting
CTRL-G I enter my Word Processing Mode. This activates Goyo, Limelight, and some special settings to help make writing prose bearable in vim.
These plugins force vim into a distraction-free writing state that almost is surreal. I can actually focus on my words without fiddling with vim commands. This mode works wonderfully in full screen mode or a window. I’ve really got to give props to the developer of these plugins because without them I wouldn’t be able to use vim every day.
The introduction of vim words and sentences has been a game changer for how I create workflows. I know can do complex text manipulation easily. For example, making a Markdown link is simple in vim. I use the Vim Surround plugin to wrap a “selection” with braces and the I can jump easily to the end of that group, place my link and then surround it with parentheses. Using the EasyMotion plugin helps with making precise movements for this operation even if it is a little slower.
Another trick I’ve picked up is turning a couple of lines into a list. I visually select the lines I was and the run the
:s command to replace the beginning of the line with the expression “- “. This command is:
:s/^/- /g. The power of regular expressions comes in handy a lot.
This is only a brief look at what I’m doing with vim. I will be posting more workflows soon as I think it’d benefit anyone who trying to learn the one true editor.