6 Vim Plugins That Will Give You Ruby Editing Super Powers

Andrew Allen
Efficient Rails
Published in
4 min readJun 4, 2015

--

You’re Aquaman, Vim is a dolphin, and Ruby is your bidding — you think it, Vim does it (provided you’re using these 6 plugins of course).

These fantastic Vim plugins will become your Ruby editing super powers. They’ll make that person looking over your should cry out, “How did you do that?!” as you bend the code to your whim as if through telepathy.

1. SplitJoin

Ruby’s syntax is so surgery that 9 out of 10 dentists won’t recommend it. This includes single-line representations for many multi-line constructs which is great for terseness and readability — until a time comes when your logic outgrows its single line and must join the ranks of its multi-line brethren. This is where SplitJoin comes in.

SplitJoin toggles between single-line and multi-line formats

With a single keystroke, SplitJoin toggles between many synonymous formats in Ruby as well as JavaScript, HTML, CoffeeScript and more.

Homepage: https://github.com/AndrewRadev/splitjoin.vim

2. Switch

Switch is SplitJoin’s little brother. While SplitJoin specializes in toggling between multi-line and single-line formats, Switch toggles a number of other miscellaneous things that you likely find yourself switching between frequently.

It’s a bit hard to explain, but they tend to fall into 2 categories:

  1. Opposites
  2. Alternate syntaxes
Switch toggles things you find yourself frequently switching between.

In Ruby, this means toggling string style, hashrocket syntax, Eruby tag types, etc.

Homepage: https://github.com/AndrewRadev/switch.vim

3. Easy-Align

Easy-Align tidies up messy code like it’s nobody’s business. Cleanly aligned code not only looks pretty, but can visually distinguish blocks of functionality and make it easier to edit consecutive values.

Easy-Align aligns blocks of text on predefined alignment rules

Easy-Align comes loaded with powerful alignment rules that work well with Ruby out of the box, but can also be extended easily for maximum alignment prowess.

Homepage: https://github.com/junegunn/vim-easy-align

4. TComment

Comment toggling is a core feature of any IDE worth its salt and TComment is my preferred comment toggling plugin for Vim. It does what’s needed of it without much configuration. Not much else to say. Those are the best kind of plugins.

TComment toggles comments

Homepage: https://github.com/tomtom/tcomment_vim

5. Surround

Tim Pope’s plugins tend to be unique in that they feel like built-in functionality of Vim itself. Surround is one of these plugins. It allows you to operate on surrounding pairs like quotes, parenthesis, brackets and even HTML tags.

Surround operates on surrounding pairs. Think quotes, parens, brackets and even HTML tags

With a familiar motion, you can change, delete and add surrounding pairs. You’ll find yourself wondering how you ever got by without it.

Homepage: https://github.com/tpope/vim-surround

6. Expand-Region

Here’s a unique way of using Vim that seems a little odd at first, but grows on you pretty quickly.

Expand-Region allows you to grow and shrink your visual selection according to Vim text objects. This means you can start with a small selection and expand it incrementally until it covers the range you want to operate on.

Since less frequently used text objects like paragraphs, methods and blocks can take a second to remember, it’s often faster to make your selection this way.

Expand-Region grows and shrinks the current visual selection

A tip for even quicker expansion: by adding the following to your .vimrc, you can grow your selection by continuing to tap v and shrink it with C-v (in case you overshoot).

vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)

Homepage: https://github.com/terryma/vim-expand-region

Want even more superpowers?

My book Efficient Rails is packed full of them. Over 120, in fact.

Pick up a free chapter at: http://www.EfficientRails.com

The 40 page free chapter includes 14 workflow upgrades (aka super powers) for conquering Rails bugs.

--

--