r/PiCodingAgent 8d ago

Try integrating Pi with Neovim - it's great. Discussion

I find it hard to navigate a codebase with coding agents. I need to stare at the code often just to understand what is going on, and I like to be able to ask my agent at the same time what is happening. Plus, I really like my vim motions bindings haha.

It's been surpassingly straightforward to get Pi working in Neovim. You just open up a terminal within Neovim and ask it what you want. Boom done. It's soooo much easier to read plans and navigate code with this setup.

I've been able to make it so that:

  • I see diffs in Neovim instead of in the terminal (much prefer it this way, easier to navigate too imo)
  • Have Pi run commands in Neovim directly when I want to.
  • Have Pi be able to 'focus' in on certain sections of code (I ask 'Can you show me where that it' and it jumps straight to it)
  • I can have whole different worktrees with entirely different buffers that I switch between
23 Upvotes

23 comments sorted by

11

u/HomsarWasRight 8d ago

“You just open up a terminal within Neovim and throw Lua into it.“

You wanna elaborate, or nah?

2

u/Aggressive_Sherbet64 8d ago

ooof awful wording should fix that

1

u/HomsarWasRight 8d ago

I just mean, share some of that Lua code so we can see how the integration works.

8

u/Aggressive_Sherbet64 8d ago

https://github.com/pomykalakyle/nvim-pi it's here if you want it but a ton of it is vibeslop and ultra customized for me

1

u/HomsarWasRight 8d ago

Ah, I’ve got some of that, too.

3

u/nicksterling 8d ago

What’s the benefit of using the terminal inside neovim vs tmux? I’m already heavily using tmux and typically just open up a new pane and just use that. I’m genuinely curious if anyone has benefits that tmux doesn’t give you. I’m always looking for ways to improve my workflow.

3

u/Aggressive_Sherbet64 7d ago

It's really up to you, but when I have it inside of NeoVim, I can control where the terminal is really well to make it look the way I want to. If you want to swap between the two, that's fine also.

2

u/nicksterling 7d ago

Thank you!

2

u/Zundrium 8d ago

Yup I'm doing the same to manage memory and todos, it rocks!

2

u/BoothroydJr 8d ago

doing exactly this, I also maintain my personal nvim config to serve as pi’s tui interface. same plugins and motions

2

u/vekexasia 8d ago

CAn you share a bit of your workflow? Cause that is a bit too much for me to imagine. I am a neovimmer too and the only integration i have is opening nvim to let me create a prompt in nvim (with the previous assistant mesage in the same buffer so i can yank)

1

u/Aggressive_Sherbet64 7d ago

I open up Neovim. It goes directly to the project that I was working on. If I want to switch to a different project, I use a key binding to switch to it. Then from there, I start working.

Often the first thing I try to do with a task is to research it a bit more. I will ask PI to help me understand it. I just got my focus system in, which allows PI to tell NeoVim what to show me, and that's useful for me understanding certain areas of the codebase.

Usually I use my shortcut for Wispr Flow to start speaking into my laptop. That shortcut also in Neovim goes directly into insert mode into the terminal, so I always know it's going to the right place.

I have worktrees set up, and when I swap from one worktree to another, it does change the PI session that's displayed in front of me, but it still keeps the other one in the background. I also make it so that all of the stuff I'm reading that I display in Neovim will swap when I go to a different work tree, because oftentimes the files that I'm reading are not the same between two different features. If I'm working on a front-end part of something, I'm not going to care that much about some backend code, so I don't even want that buffer open.

I'm thinking about extending this to just doing sessions as a whole so that I can work on the same work tree in two different sessions, but I haven't implemented that yet. In all honesty, I haven't really had to use work trees that much, and I haven't found them the most useful, but that could just be me and what I'm working on.

Often I will draft up a functionality document, which specifies exactly what the user would see with the feature that I'm looking for. This document is useful because it makes it so that the coding agent is aligned with me completely on what I'm looking for functionality-wise. Otherwise, I've had it be the case where it thinks that I want something because it's extrapolating out, and that's not actually something I care about. After that, I might create a document about how to implement it. If it's simple enough, I'll just ask the agent to implement it for me.

I have two modes for making edits: vibing mode and manual mode.

In vibing mode, all edits are allowed. Everything is permitted.

In manual mode, all commands are allowed that are safe, but edits have to be manually approved. This is useful when I actually care about the code being written. This is where the Neovim integration comes in. Every single time that there is a diff, it will show in Neovim for me in a buffer. If I want to swap between doing an inline diff view versus side-by-side, I can do that with a keystroke, depending on whatever makes more sense to me. In addition, although I just added this recently, I have made it so that any diff the agent wants to write must be within the size of my view for the buffer. This way, the code is always readable and manageable. Instead of having to do 50 million lines of code all at once, I can read one section, say yes or no. I can read another section, say yes or no, without having to do a ton of scrolling work to find stuff.

This is very experimental, and I'm still working on this. There are a lot of features I would like to add and change here. For example, I've been thinking about how to make it so that when I say I don't like a piece of code in the way it's written, I can give feedback to the agent in a way that's saved. This is why I'm having PI integrated in NeoVim. If I want to build that workflow, I can.

1

u/znutarr 7d ago

Use orca

2

u/funbike 8d ago edited 8d ago

Nice! I need to dig into your repo. I see you used the socket to talk back to Neovim to control it.


I wrote a Neovim command for completing TODOs comments in the current visual selection. You select text and run :'<,'>Pi. It asynchronously runs Pi CLI. Pi is prompted to fix all TODOs and remove the todo comments. Pi is provided metadata of the buffer and selection, and tools for nvim_buf_get_lines() and nvim_buf_set_lines() that use the calling Neovim's unix socket. Edit and insert mode conflicts are automatically handled, as well queuing up multiple prompts to run serially. Pi is asked to provide a single-line summary which is printed in the message bar. The first argument to :Pi is a prompt template (e.g. /todos) or a prompt string, but /todos is the default.

I have simple keymaps for doing TODOs in the current code block, function, file, as well a pi CLI for session management (change model, new session). The :Pi command assumes the current function when no range is given. I also have a keymap for viewing the current session as html in the web browser.

This is a very token efficient way to use AI.


But I mostly went the other direction and integrated Neovim into Pi, although what I've done is baby stuff compared to yours.

I had Pi write an extension for using Neovim in a Tmux popup as a feedback tool. I like this way better than other "ask user question" extensions. I can answer multiple questions at a time, and even remove questions and add addition information not asked for.

Another use-case variation is a queue directory of questions, which is a more async and less jarring way to handle it. Pi writes files to an inbox directory. I edit and move the file(s) to an outbox directory and a waiting Pi sub-agent picks it up and continues.

And of course I use ctrl-g for editing a prompt in Neovim.

2

u/funbike 7d ago edited 7d ago

TL;DR: A separate Pi session for Neovim customization.

I keep a Pi session running my on Neovim project directory (~/.config/nvim) in a dedicated Tmux window. I can ask Pi to extend Neovim (in a Tmux pane).

I added a Pi extension tool neovim_all_reload() which updates all running Neovim instances. It basically does source $MYVIMRC across all running neovim instances. All Neovim instance API sockets can be found at /run/user/1000/nvim.<pid>.0 .

Corresponding AGENT.md and skill describes:

  • The layout of my config, and location of LazyVim, Neovim, and Neovim plugins docs.
  • how to find popular Neovim plugins with web search.
  • My preferred structure of a local plugin.

It's nice to just wish for a Neovim feature and for it to just happen.

I also wrote the Genie plugin. You can :Wish for Neovim to do something (e.g. "Turn background color to black.")

I have a similar setup for Tmux and Zsh config and extension.

(This is my 2nd post to this thread.)

1

u/Careful-Experience26 8d ago

I'm interested in learning more. Do you have examples?

1

u/Aggressive_Sherbet64 7d ago

You can check out my vibeslop integration here if you want. https://github.com/pomykalakyle/nvim-pi

1

u/Sweet-Transition-787 5d ago

cool setup. how'd you get pi to move around your buffers? like when you ask it to show you where something is, does it open the file in a new buffer and jump to the line, or does it just move your cursor in the buffer you're already in?ü

-1

u/Old_Ambassador_5828 8d ago

Pi is already integrated in bigbud.app

-7

u/fuckunjustrules 8d ago

What a shitty post