Sometimes youβre hacking away in iex
, and you want to write a multi-line Elixir expression β maybe a small script, a complicated pipeline, or just something too big for a single line. Did you know you can drop into your favorite editor right from iex
, write your code comfortably, and then execute it?
In your terminal, set the VISUAL
environment variable to your editor of choice:
export VISUAL=nano # or vim, nvim, code, emacs, etc.
You can also add this to your shell config (~/.bashrc
, ~/.zshrc
, etc.) to make it permanent.
Inside an iex
shell, press:
ESCAPE + o
(Thatβs the Escape key, then the letter o.)
This will launch your configured editor in a temporary file. You can now write multi-line Elixir code just like you would in a .exs
file.
Once you're done, save and quit the editor (:wq
in Vim, Ctrl+O + Ctrl+X
in Nano), and IEx will execute the code you just wrote.
Note: if you want to get the syntax highlighting correctly, then need need to associate tmp.*.erl
with the Elixir language.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.