A minimal Neovim plugin that integrates Pi Agent as an interactive terminal powered by snacks.nvim.
- Interactive Terminal - Open Pi Agent directly in Neovim
- Send Visual Selections - Select code in visual mode and send it to Pi Agent with file context (e.g.,
@lua/pi/init.lua#L1-15) - Send File Context - In normal mode, send the current file reference to Pi Agent (e.g.,
@lua/pi/init.lua)
demo.mp4
- Neovim >= 0.10 (required by snacks.nvim)
- snacks.nvim
- Pi Agent CLI (
picommand)
{
"bamggm/pi.nvim",
dependencies = { "folke/snacks.nvim" },
keys = {
{ "<leader>ap", "<cmd>PiSendFile<CR>", desc = "Send file to Pi Agent" },
{ "<leader>ap", "<cmd>PiSendSel<CR>", mode = "v", desc = "Send selection to Pi Agent" },
{ "<leader>ao", "<cmd>PiOpen<CR>", desc = "Open Pi Agent" },
},
}Use pi.nvim's keys option to set terminal keymaps (scoped to the snacks terminal window only):
{
"bamggm/pi.nvim",
dependencies = { "folke/snacks.nvim" },
keys = {
{ "<leader>ap", "<cmd>PiSendFile<CR>", desc = "Send file to Pi Agent" },
{ "<leader>ap", "<cmd>PiSendSel<CR>", mode = "v", desc = "Send selection to Pi Agent" },
{ "<leader>ao", "<cmd>PiOpen<CR>", desc = "Open Pi Agent" },
},
opts = {
keys = {
["<C-h>"] = "<Cmd>NvimTmuxNavigateLeft<CR>",
["<C-j>"] = "<Cmd>NvimTmuxNavigateDown<CR>",
["<C-k>"] = "<Cmd>NvimTmuxNavigateUp<CR>",
["<C-l>"] = "<Cmd>NvimTmuxNavigateRight<CR>",
},
},
}require("pi").setup({
command = "pi", -- Pi CLI command
focus_on_sel = true, -- Focus terminal after sending selection
keys = {}, -- Buffer-local terminal mode keymaps
-- snacks terminal options
terminal = {
interactive = true,
win = {
position = "right",
width = 0.30,
height = 0,
relative = "editor",
},
},
})| Option | Type | Default | Description |
|---|---|---|---|
command |
string | "pi" |
Pi CLI command |
focus_on_sel |
boolean | true |
Focus terminal after sending selection |
keys |
table | {} |
Buffer-local terminal mode keymaps (e.g. { ["<C-h>"] = fn }) |
terminal |
table | (see above) | snacks terminal options |
| Command | Description |
|---|---|
:PiOpen |
Open Pi Agent in a terminal window |
:PiSendSel |
Send visual selection to Pi Agent |
:PiSendFile |
Send current file reference to Pi Agent (normal mode) |
- Select code in visual mode (
v,V, orCtrl+v) - Press
<leader>ap - The selection is sent with file and line context
- Interact with Pi Agent in the terminal
- In normal mode, press
<leader>ap - The current file reference is sent (e.g.,
@lua/pi/init.lua) - Interact with Pi Agent in the terminal
piis an external process to Neovim so editor buffer is not refreshed and can conflict if you have unmodified changes. You can use:e!(:help edit!) to reopen the file discarding any unmodified changes.
- Uses the
folke/snacksterminal module and launchpiprocess. That's all. Nothing fancy.
Consider other options to use Pi agent along with Neovim:
MIT License - see LICENSE file for details.
Contributions are welcome! Feel free to submit issues and pull requests.