Run Elixir via IEx inside Neovim! 🧪
Q: Why use IEx.nvim at all when you can just run iex or mix run from the command line?
A: Because inside Neovim you get all of your LSP, snippets, autocompletions, hotkeys, etc. It's a more pleasant coding experience, and IEx already natively supports reading from .iex.exs as a persistent scratch file convention.
-
Install using your favourite package manager:
Using lazy.nvim:
{ "jesseleite/iex.nvim", lazy = false, opts = { -- All of your `setup(opts)` will go here when using lazy.nvim }, } -
Optionally map some keybindings:
vim.keymap.set("n", "<Leader>io", vim.cmd.IEx, { desc = "Open IEx scratch file" }) vim.keymap.set("n", "<Leader>ir", vim.cmd.IExRun, { desc = "Run IEx in vsplit" })
-
Optionally add
.iex.exsto your global git excludes, so that you don't have to ignore it in each project. -
Order a tasty elixir! 🥃 🤘 😎
Run :IEx to open (or create) an .iex.exs scratch file in your current working directory.
Simply :w the buffer (or run :IExRun) to evaluate your scratch file and display the output in a vertical split.
The .iex.exs scratch file is automatically read by Elixir when running iex on the CLI, so IEx.nvim uses the same first-party scratch file convention by default.
When running, it uses mix run .iex.exs under the hood, which is essentially the same as iex -S mix, but doesn't keep the session open. This process will read your scratch file, display output, and exit the process for you.
As for output, the last expression in your scratch file is automatically inspected and displayed, unless it already contains a dbg or IO.inspect call. Feel free to use your own dbg or IO.inspect calls throughout your scratch file as well.
The default configuration:
require("iex").setup {
scratch_file = ".iex.exs",
output_buf_name = "iex:///output",
run_on_save = true,
}| Option | Default | Description |
|---|---|---|
scratch_file |
".iex.exs" |
File name of the scratch file created in your project root |
output_buf_name |
"iex:///output" |
Buffer name displayed when running and viewing output |
run_on_save |
true |
Whether or not to automatically run :IExRun on save |
Thank you for checking out IEx.nvim!
Here's where can find me on the internet...
jesseleite.com
Software Developer @ SavvyCal
X
My Neovim config
My NeovimConf talk on macros 📺
