Open or reuse a Rex agent pane from Neovim, start a configurable agent (pi by default), and seed the current file plus line range without submitting Enter.
Requires Neovim running inside Rex (REX_SESSION, REX_BLOCK, and REX_SERVER in the process environment).
With lazy.nvim:
{
"athul-ramesh/rex-agent.nvim",
main = "rex_agent",
opts = {},
}If LazyVim's Claude Code extra owns visual <leader>as, free that key:
{
"coder/claudecode.nvim",
optional = true,
keys = {
{ "<leader>as", false, mode = "v" },
},
}Press <leader>as in normal or visual mode on a saved file buffer.
- First press opens the agent pane labeled
nvim-agentand starts the agent. By default that pane is a floating layer to the right of the editor; setpane = "right"to open it in a horizontal split beside the anchor block instead. - Later presses reuse the existing pane (floating or split), seed context again, and focus it. In floating mode, a tiled agent block is raised into a float first.
- The seed is
@rel/path#L131for one line and@rel/path#L131-140for a range, relative to Neovim's cwd. Finish the prompt and press Enter yourself.
With multiple profiles and no default, the main map opens an agent picker. Per-profile keys or ask("name") seed a specific agent without the picker.
Pass fields through lazy opts, or call setup directly.
require("rex_agent").setup({
agent = { "pi" },
label = "nvim-agent",
keys = "<leader>as",
pane = "floating",
})agent may be a string or an argv list. Set keys to false to skip the main map. pane is "floating" or "right".
Omitting profiles synthesizes one profile whose name is the label. The main map seeds it directly with no picker.
require("rex_agent").setup({
keys = "<leader>as",
pane = "floating",
default = "pi",
profiles = {
{ name = "pi", argv = { "pi" }, label = "pi" },
{
name = "claude",
argv = { "claude" },
label = "claude-code",
keys = "<leader>ac",
},
{ name = "devin", argv = { "devin" }, label = "devin" },
},
})nameis the handle forask("name").labelis the Rex block label.argvis a non-empty list of strings (command plus args).- Per-profile
keysbind that profile directly and skip the picker on that chord. defaultmust name a profile. When set,ask()and the main map seed that profile with no picker.- One profile and no
defaultalso skips the picker. keys = falseon setup omits the main chooser map. Per-profile maps still bind.paneapplies to every profile in the catalog.- Do not pass
profilestogether withagentorlabel.
- Unsaved or non-file buffers are refused.
- Neovim outside Rex is refused.
- Files outside Neovim's working directory, paths with
#, or./..segments are refused. - Create uses
shell=nonewith the agent resolved via Neovimexepath, and prepends Neovim'sPATHso shebangs likeenv nodestill resolve.