Skip to content

Link to your editor

Robin Daugherty edited this page Oct 28, 2020 · 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 or puma-dev for managing multiple web applications see Running in Puma dev or 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.

Supported editors

Better Errors supports the following editors.

See BetterErrors::POSSIBLE_EDITOR_PRESETS for more details.

Atom

Atom v1.23 added support for open/file URLs.

Install the Shell Commands from within Atom and add the following to your shell config:

export EDITOR="atom"

Emacs

Add the following to your shell config:

export EDITOR="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

Add the following to your shell config:

export EDITOR="idea"

The URL is idea://open?file=%{file}&line=%{line}.

MacVIM

Add the following to your shell config:

export EDITOR="vim"

The URL is mvim://open?url=file://%{file}&line=%{line}.

In iTerm

Instructions are in phallstrom/urlscheme_vim_in_iterm.

RubyMine

Add the following to your shell config:

export EDITOR="rubymine"

The URL is rubymine://open?file=%{file}&line=%{line}. If this doesn't work, please try x-mine://open?file=%{file}&line=%{line}.

Sublime Text

Add the following to your shell config:

export EDITOR="subl -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.

(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.)

The URL is subl://open?url=file://%{file}&line=%{line}.

TextMate

TextMate-compatible URLs are 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.)

Visual Studio Code

Install the command-line tools

Add the following to your shell config (on MacOS put this in ~/.bash_profile :

export EDITOR="code --wait"

(The --wait 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. Also very handy for credentials.yml.enc in Rails >5.2).

Editors not supported

Is your preferred editor missing? Please open an Issue or Pull Request.

Panic Nova

Nova does not currently support opening files through a nova:// scheme URL.

Forcing a specific editor

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 must configure Better Errors this way, add config/initializers/better_errors.rb to your global .gitignore or the project .gitignore file.

Place the following in config/initializers/better_errors.rb:

if defined?(BetterErrors)
  BetterErrors.editor = :txmt
end

If you're using an editor that is not supported directly by Better Errors, you can provide a formatting string, for example:

if defined?(BetterErrors)
  BetterErrors.editor = "vscode://file/%{file}:%{line}"
end

Or if you need to change the way the string is assembled, you can provide a proc, for example:

if defined?(BetterErrors)
  BetterErrors.editor = proc { |file, line|
    "vscode://file/%{file}:%{line}" % { file: URI.encode_www_form_component(file), line: line }
  }
end

Clone this wiki locally