EdEEX is a Neovim plugin for editing embedded Phoenix LiveView templates, inspired by Org Modeʼs org-edit-src-code
.
This plugin depends on nvim-treesitter
and the Elixir Tree-sitter grammar.
Use Neovimʼs built-in packages feature (:h packages
) or a plugin manager—Packer comes to mind:
use {"ngscheurich/edeex.nvim", requires = "nvim-treesitter/nvim-treesitter"}
EdEEx has two primary functions, edit
and apply
. While these can be called directly, it is highly recommended to set up a key mapping using the setup
function.
You can combine installation and setup into a single Packer form for convenience:
use {
"ngscheurich/edeex.nvim",
requires = "nvim-treesitter/nvim-treesitter"
config = function ()
require("edeex").setup({mapping = "<C-c>e"})
end
}
Assuming you have configured EdEEx as above, and have the following Elixir code:
defmodule AppWeb.HelloLive do
use Phoenix.LiveView
def render(assigns) do
~L"""
<section>
<header>
<h1>Hello, <%= @name %>!</h1>
</header>
</section>
"""
end
def mount(_params, %{"name" => name}, socket) do
{:ok, assign(socket, :name, name)}
end
end
Placing the cursor anywhere inside of the embedeed HEEx template and pressing <C-c>e
will open a scratch buffer with the following contents:
<section>
<header>
<h1>Hello, <%= @name %>!</h1>
</header>
</section>
The bufferʼs filetype
is set to eelixir
and it inherits the indentation settings (shiftwidth
, tabstop
, and softtabstop
) from the source buffer. By pressing <C-c>e
in this buffer, any changes made to it will be applied to the source buffer.
Name | Default | Description |
---|---|---|
mapping |
nil |
Key mapping to enter and exit the edit buffer (Normal and Insert mode) |
split |
true |
Open a horizontal split when summoning the edit buffer |
autoformat |
true |
Format EEx code when entering and leaving the edit buffer |
This is a very beta-level plugin and could get broken or abandoned at any time. Use at your own peril!