The initial publication of this article was attributed to the wrong author. This has been fixed and those responsible have been sacked. Sorry David!
Web Development has evolved tremendously in the last 20 years. A modern development environment would be unrecognizable to to someone developing Coldfusion in the late ’90s for example. The greater focus on best practices and developer productivity have certainly made software more maintainable, but this comes at the cost of added complexity. To navigate this complexity, a modern development environment is required; this article will outline some of my personal favorite tools.
Tmux is a terminal multiplexer (think screen), which means you can have several terminals in the same shell session. It allows you to split panes and move them around and reconnect to a tmux session from a different machine. This particularly shines when it is deployed on a server, as you can start a long-running task, disconnect, and your tmux session will keep running.
The real strength in Tmux for development lies in knowing in which window each of your different tools is running because with some quick window changing shortcuts, you can move so quickly that flow becomes instinctual. To aid this, tmuxinator sets up profiles (protip: bind these to Tmux shortcuts to facilitate easy opening of different types of projects like Rails, Sinatra, etc), which complements Tmux nicely.
If you are looking for a simple start with Tmux, check out this article.
Bash is fine and all, but it hasn’t aged very well and better terminal alternatives are available. ZSH is an excellent choice, but I personally lack the motivation to invest time in learning how to configure yet another piece of software. To this end, I would recommend Fish. It has excellent command completion, is fully scriptable, and looks much nicer than Bash. Best of all, it just works out of the box (although there are a couple of minor idiosyncrasies you’ll run into. Also, your Bash aliases won’t work, but translating is straightforward and these are comparatively low setup costs). I particularly enjoy interfacing with Git this way, but I recently discovered the excellent Gitsome, which offers excellent Github integration and unparalleled autocomplete, so I am currently vacillating between the two.
Vim is the cornerstone of my environment. Heavily customized to speed development, it bears more of a resemblance to a fully fledged (albeit lightweight!) IDE. Let’s walk through some generally useful plugins, and then get to some Ruby-specific ones. You can download my vim dotfiles here.
Navigating a project can be cumbersome. Fortunately, Vim’s rich ecosystem really comes into its own here. For browsing a project, I recommend the excellent Nerdtree. This will give you a browsable tree structure, affording you a neat high-level overview of the current directory and its children. Pressing
m while in this view will allow you the ability to delete, create, and rename nodes without ever leaving vim. Sublime stalwarts will enjoy ctrlp; an excellent fuzzy matcher which particularly shines when you have similarly named files, like in a Rails project for example. Finally, I frequently want to access files I have used recently; MRU does exactly this.
While those are some of my favorites, here are some other vim plugins that deserve special mention:
* Fugitive: Git integration directly in Vim
* Supertab: Code completion
* Airline: Pleasant looking status bar
* TComment: Quick comment/uncomment functionality
* Surround: Wrap the usual vim boundary selections in parenthesis or quotes
* Autoclose: Automatically close brackets or quotes
* Gundo: Interface to Vim’s well hidden tree structure storing document changes, which frequently proves much more useful than the linear ‘undo’ functionality
Ruby Specific Plugins
First up, you need to ensure your version of Vim is compiled with Ruby:
vim --version | grep ruby
The above command should include a
+ruby. If it doesn’t, you need to either recompile Vim with ruby support (relatively trivial) or install a version of Vim with Ruby support, like MacVim. While a lot of the plugins will work without it, you’ll miss out on useful features like autocompletion.
vim-ruby is the first port of call. It adds syntax highlighting, IntelliSense-like autocompletion, and even compiler plugins. This should get you a lot of basic IDE functionality out of the box. It even has erb syntax highlighting!
Tim Pope is the man who has given us several excellent Ruby (and other) plugins. You could do worse than to check out his projects and integrate them into your workflow. If you’re going to get one plugin to aid your Rails development, it should be vim-rails. This plugin brings all the command line functionality directly into Vim, which is tremendously useful when you marry it up with Vim shortcuts. Let’s delve into some useful commands here:
gf – This is a context aware switch that will jump you right into a related file. You can leverage the appropriately named
:A (alternate) and
:R (related) to go from model to schema, template to helper, and controller to functional test.
rails on the command line with
:Rails (also rake can be accessed via
:Rake, if you’re pre-Rails 5.)
You can extract partials by visually selecting an area and leveraging
:Rextract <filename>. This seems such a minor feature but is incredibly useful when refactoring a clumsy view.
There are a ton of other useful shortcuts and your time will be well invested in learning them.
vim-dispatch is another Tim Pope creation. This allows you to leverage Tmux to bring asynchronous functionality to Vim. Useful to kick off unit tests without blocking input or opening another pane.
vim-rspec is a lightweight RSpec runner for Vim. I enjoy the mappings if I’m not using Guard.
For further reading on this subject, check out this article which is much more in depth.
- vim-endwise: automatically appends an
endwhen you input
def <function_name>. Think snipmate but without having to invoke the shortcut.
- vimbundler: wraps bundler, which makes interfacing with it slightly nicer.
- vim-haml: Cutting edge Vim runtime files for Haml, Sass, and SCSS – unnecessary but nice.
This isn’t really a Vim plugin but I’ll include it here anyway: gem-browse is a Ruby Gem that opens a library’s source file in your editor, which saves time when you need to wade through the source of some obscure library to see why your code isn’t executing as expected.
Docker is comparatively new technology compared with the others, but no less important. It facilitates easy and platform agnostic deployment by running a ‘container’ within a single Linux instance, avoiding the overhead of starting and maintaining traditional Virtual Machines. Additionally, the isolation afforded by this approach affords an extra layer of protection.
I am a huge fan of Guard. While in large projects with huge batteries of tests, it doesn’t shine so much, any rapidly evolving project without this constraint benefits hugely from the instant feedback it provides to developers. By keeping the Spring preloader going, it can dramatically reduce time taken for tests to run, and I would wholeheartedly recommend pairing it with minitest-reporters for more informative test output.
Pry is a fantastic addition to your gemset. A powerful alternative to irb, it allows command shell integration (git, vim, etc), syntax highlighting and powerful history viewing and replay functionality. Used in tandem with the pry-doc gem, it includes some neat features like
show-doc to bring up documentation and
show-source to view source of Ruby builtins. It can work well as a debugger and as someone who favors REPL driven development, I find it a breath of fresh air to use compared with the default irb.
With the advent of ORMs, SQL is something I interface with less regularly, which means autocomplete is a real time saver when I can’t remember exactly how to do something. Pgcli (and its cousin Mycli if you’re stuck with mysql) offer this exact functionality and with syntax highlighting to boot. Highly recommended.
If you can suffer through what is arguably the most painful configuration process in modern software, Mutt is an excellent choice for command line email access. It uses Vim bindings and I definitely appreciate not having to leave my shell to handle email.
We’ve covered a lot of ground here and, as always, there’s a ton more below the surface. Vim is where I spend most of my time, so I’ve spent proportionally much more time customizing it. Researching Tmux and your shell properly is definitely time well-spent. Naturally, this is all personal preference so you’re unlikely to develop using my exact setup, but you should hopefully have a better idea of what is out there and perhaps even integrate something new from here into your workflow.
David Bush is a Web Developer who travels the world and writes code. His favourite languages are Clojure, Ruby and Python. He enjoys learning new technologies, beer, good food and trying new things. www.david-bush.co.uk
The Principles of Beautiful Web Design, 4th Edition
Learn PHP in One Day and Learn It Well
Docker for Web Developers