My greatest hurdle when learning to work with Vim was establishing a flow. Most editors, even most applications in general, use a tabbed interface that’s become so universal almost all apps implement the same keyboard shortcuts. Naturally then, I jumped into Vim without realizing how much this preconception would work against me.
Past experience told me to run one instance of Vim, a tab for each project, and multiple windows within each tab. That alone is a step up from most other editors. So I learned the tab commands and how to manage multiple current working directories, an issue I realized is merely a symptom of the larger problem – Vim wasn’t built this way! In fact, tabs were only recently added in version 7.0, over a decade after the initial release.
Finally I’ve learned running multiple Vim instances makes for a far better workflow. This usually isn’t an option with other editors but Vim is so fast and lightweight that changing my fundamental approach has definitely increased my productivity. The key is customizing a separate environment for each project or even each individual task. Any terminal tool that splits windows would work but I’ve come to like Tmux since it’s available on all of my workstations and servers.
I begin by checking for existing Tmux sessions. If none exist, I attach to a new session with the same name as my user. When starting a new task, no matter how small it may seem initially, I create a new Tmux window with a very descriptive name – say “check qa diskspace” or “calendar widget bug” for example. Within that window I then customize an environment for the task at hand. That could consist of Vim splits, Tmux splits, SSH connections, tailing files, or anything else that happens along the way. The possibilities are endless but generally it’s just a split or two.
The real benefit is the entire development environment becomes a cheap resource. That’s a radical departure from the massive software suites we know and love. Creating new environments takes seconds. Tweaking an environment only affects the current task, so far less time is spent rearranging windows and files. Performance is unaffected by dozens, probably even hundreds, of environments. Keep one around for an issue that might popup again next month because it doesn’t cost anything. Switching contexts becomes instantaneous as long as the old brain can keep up!