Skip to content

bamggm/pi.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pi.nvim

A minimal Neovim plugin that integrates Pi Agent as an interactive terminal powered by snacks.nvim.

Features

  • 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

demo.mp4

Requirements

Installation

lazy.nvim

{
  "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" },
  },
}

Tmux Users (Optional)

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>",
    },
  },
}

Configuration

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",
    },
  },
})

Options

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

Usage

Commands

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)

Sending Code to Pi Agent

  1. Select code in visual mode (v, V, or Ctrl+v)
  2. Press <leader>ap
  3. The selection is sent with file and line context
  4. Interact with Pi Agent in the terminal

Sending File Context to Pi Agent

  1. In normal mode, press <leader>ap
  2. The current file reference is sent (e.g., @lua/pi/init.lua)
  3. Interact with Pi Agent in the terminal

FAQ

  • pi is 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.

How it works

  • Uses the folke/snacks terminal module and launch pi process. That's all. Nothing fancy.

Alternative

Consider other options to use Pi agent along with Neovim:

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit issues and pull requests.

About

A minimal Neovim plugin that integrates Pi Agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages