Atom Editor: Tricks, Plugins & Shortcuts for Ruby Developers!

If you are using Atom for Ruby development then you probably know that there are plugins (packages in Atom) that can improve your productivity with the editor.

But Atom’s package repository has thousands of packages!

Which ones should you be using?

And on top of that, what are some useful keyboard shortcuts you can use to work faster?

If you are an Atom user you’re going to love this article because that’s exactly what I cover here!

Best Atom Packages

Atom packages add new functionality to the editor. They can be installed from the editor’s interface itself.

Open your settings (CTRL + ,) & click on the “Install” tab.

atom-install-package

You can type in that search box to install the recommended packages.

Atom Runner

The first package I want to recommend is called “atom runner”.

This package allows you to run code directly inside your editor. The output will appear in a split window on the right (on the bottom if you have Atom 1.17 or newer).

It looks like this:

atom-runner

To install it simply search for its name on the package manager window & click “Install”.

Then to launch it make sure your file type is set to Ruby & then press ALT + R (CTRL + R on Mac).

Note: If it doesn’t work try opening Atom from a terminal, instead of a menu or desktop icon.

If you want to increase the font size:

First open Atom’s style sheet file (with CTRL + ALT + P, type “osty”, then enter).

Then add this to the file:

.stdout {
  font-size: 18px !important;
}

Block Convert

You may want to convert between the do...end & { ... } block format. You can save yourself some work by using the “block convert” package.

With this package installed position your cursor inside a block, open the command-palette (CTRL + ALT + P) & search for “converter”, then select either “to do end” or “to curly brackets”.

This GIF demonstrates this package in action:

block-convert

Toggle Quotes

You can easily switch between single & double quotes with the “toggle-quotes” package.

To use it position your cursor inside the pair of quotes you would like to switch then press CTRL + " (or CMD + " on a Mac).

Linter Ruby

A linter is a tool that points out errors in your code.

Mostly syntax errors, so don’t expect any miracles here 🙂

This helps you find these errors faster without even having to run your tests.

You can install the “linter-ruby” package if you want to enable linting in your editor.

Other Atom Packages

Atom Keyboard Shortcuts

Everyone loves shortcuts!

Let me give you a table with some of my favorites:

Shortcut Description
CTRL + D Multi Selection
CTRL + F Search in current file
CTRL + P Search for files in current projects (quick open)
CTRL + B Switch between open files
CTRL + ALT + 7 Toggle comments for selected code
CTRL + UP / DOWN Move current line up & down
CTRL + Shift + K Delete current line

Here’s a GIF demonstrating the multi-select feature:

atom multi select

You can find even more shortcuts here:

https://github.com/nwinkler/atom-keyboard-shortcuts

How to Use Atom Snippets To Boost Your Productivity

Snippets allow you to create expandable templates to write code faster.

For example, you can type def & the enter key.

That will create a method template for you. It will also put your cursor on the method name so you can start typing right away.

After that you can press the “tab” key & it will place your cursor inside the method body.

Pretty useful, right?

Once you get used to it you will be doing this all the time.

Here’s a list of some useful built-in Ruby snippets:

Snippet Description
if if / end
ife if / else / end
def def / end
defs def self.name / end
deft def test_ / end
cla class / end
mod module / end
ea each { … }
beg begin / rescue / end
Hash Hash.new { … }
File File.read
r attr_reader
w attr_writer
rw attr_accessor

There are also ERB specific snippets, like = for <%= %> and - for <% %>.

Notice that your file type needs to be set to “Ruby” for these snippets to work. This happens automatically if you are editing a file with a .rb extension.

In addition, you can create your own snippets.

To do that just open your command palette (CTRL + ALT + P) & type “osni” then press enter.

A file will open where you can define your custom snippets.

A snippet looks like this:

".source.ruby":
  "Initialize":
    prefix: "init"
    body: "def initialize\n\t$1\nend"

Where the first string is the language for this snippet, then we have the name for this snippet (can be anything), and “prefix” is the actual word that will trigger the snippet, “body” is the code template.

If you have multiple snippets you don’t want to repeat the language part (.source.ruby), you just group everything under there, properly indented.

Notice the $1 here, that represents where the cursor is going to be positioned after the code snippet is inserted.

You can also have more than one of these cursor things.

Example:

"test":
  'prefix': 'test'
  'body': 'def test_$1\n\t$2\nend'

When you press “tab” your cursor will go to $2, then $3, etc.

Think about what things you have to type often that are not already covered by built-in snippets, then write your own custom snippet for that.

How to Auto Indent Your Code

Sometimes your indentation can get out of whack & it’s a pain to fix it by hand…

Atom has you covered because it comes with an “Auto Indent” feature.

To use it select the code you want to indent, open the command palette (CTRL + ALT + P), then search for “auto”.

Built-In Git Integration

Atom includes Git integration since version 1.18.

To use it make sure the file you are editing is part of a project with an initialized git repository.

Note: You can also initialize the repository from inside the editor for new projects.

Then look at the lower right, it will say something like “3 files”.

atom git panel

Click on that & the Git panel will open where you can see the changes you made by clicking on each file.

Also you will be able to commit your changes by staging your changes, adding a commit message and clicking the “commit” button at the bottom of this panel.

Summary

In this article you learned how to become a more productive Ruby developer by installing useful packages, learning about keyboard shortcuts & defining custom snippets!

Like this? Don’t forget to share this article so more people can benefit from it 🙂

3 thoughts on “Atom Editor: Tricks, Plugins & Shortcuts for Ruby Developers!”

  1. Thanks for sharing! The snippet session didn’t work for me though. I fixed it by including the context:

    ".source.ruby":
      "Initialize":
        prefix: "init"
        body: "def initializent$1nend"
    

Comments are closed.