Skip to content

Link to your editor

Robin Daugherty edited this page Nov 4, 2017 · 39 revisions

Better Errors includes a link to the source code when you're looking at any exception.

link directly to the line and file in your editor

Configuring

By default, your EDITOR environment variable is used to determine which editing application you prefer. If you haven't set EDITOR, that would be a good first step for making development easier.

Some editors require you to take steps to install their command-line tool, and then you'll need to modify your ~/.bashrc (stock macOS) or ~/.zshconfig (if you use ZSH).

If you are using Pow, a tool for managing multiple web applications on Mac, see these instructions to configure Pow.

If you are using Vagrant, Docker, or another virtualization mechanism, you may need to configure it to have the correct location of the source files on your machine. See Running on virtual machines.

Forcing your preference upon your team

You can configure your Ruby project to force Better Errors to link to a specific editor, but this is not recommended, since each developer on your project may prefer a different editor.

If you want to do this even though it is not recommended, in a Rails project, place this in config/environments/development.rb:

if defined? BetterErrors
  # Force all developers on this project to use Textmate, even if they prefer something else.

  BetterErrors.editor = :txmt
end

or if you are using an editor that is not supported directly by Better Errors, you can use:

if defined? BetterErrors
  # Force all developers on this project to use VS Code, even if they prefer something else.
  BetterErrors.editor = "vscode://open?url=file://%{file}&line=%{line}"
end

Supported editors

Better Errors supports the following editors:

Emacs

This is enabled if $EDITOR contains "emacs". The URL is emacs://open?url=file://%{file}&line=%{line}.

Using Firefox

You'll need to register the emacs:// protocol in Firefox. Also, Firefox will pass a lot of junk to the command, here's a suggestion for your bin/ folder: https://gist.github.com/nofxx/6987409

IntelliJ IDEA

This is enabled if $EDITOR contains "idea". The URL is idea://open?file=%{file}&line=%{line}.

MacVIM

This is enabled if $EDITOR contains "vim". The URL is mvim://open?url=file://%{file}&line=%{line}.

In iTerm

Instructions are in phallstrom/urlscheme_vim_in_iterm.

RubyMine

This is enabled if $EDITOR contains "rubymine". The URL is rubymine://open?file=%{file}&line=%{line}.

Sublime Text

This is enabled if $EDITOR contains "subl". The URL is subl://open?url=file://%{file}&line=%{line}.

Add the following to your shell config:

export EDITOR="mate -w"

You'll need to install subl handler or something similar.

If you installed a sublime URL handler before August 2017, please see this security advisory and remove your old URL handler.

TextMate

This is enabled by default, or if $EDITOR contains "mate". The URL is txmt://open?url=file://%{file}&line=%{line}.

Add the following to your shell config:

export EDITOR="mate -w"

(The -w causes the command line tool to wait until you close the file before it continues. This is necessary for tools like git, where it must wait for you to edit the file before continuing.)

Editors not natively supported

Support for these should be added to Better Errors soon.

Atom

(Currently Atom uses the atom:// scheme, but it does not properly handle it. Until the project fixes this issue, it is necessary to use a different scheme and install a custom URL handler.)

Place this in config/environments/development.rb:

BetterErrors.editor='atm://open?url=file://%{file}&line=%{line}' if defined? BetterErrors

You will need to install one of the following:

RubyMine

Place this in config/environments/development.rb:

BetterErrors.editor='x-mine://open?file=%{file}&line=%{line}' if defined? BetterErrors

Visual Studio Code

Set up the following config:

BetterErrors.editor = "vscode://open?url=file://%{file}&line=%{line}" if defined? BetterErrors

You'll need to install the vscode-handler extension.

Clone this wiki locally