ECTO_EDITOR with Visual Studio Code

ECTO_EDITOR is a cool feature within ecto_sql. From the docs:

This generator will automatically open the generated file if you have ECTO_EDITOR set in your environment variable.

Until now, I hadn’t gotten it to work. But, researching for this post I figured it out. If you add the following to your .bashrc or .zshrc file, Ecto will conveniently open your editor for you:

export ECTO_EDITOR="code -rg"
# the -r flag tells it to reuse the current window
# the -g flag tells it to go to the line number specified

This assumes you have installed VS Code’s CLI tool on your PATH.
For Mac, look here: Installing Visual Studio Code on macOS
For other platforms, I think it’s automatically set up for you.

Hopefully this helps someone else that’s looking to fine tune their Ecto + VS Code integration!

6 Likes

There is also PLUG_EDITOR

2 Likes