madox2 / vim-ai

AI-powered code assistant for Vim. OpenAI and ChatGPT plugin for Vim and Neovim.
MIT License
699 stars 59 forks source link

Ask original buffer modification from AIChat #58

Open MartinDelille opened 11 months ago

MartinDelille commented 11 months ago

I'm not sure if it is possible but I would like to be able to modify the buffer content from the AIChat buffer.

Currently if I want to edit a buffer, I have to select the portion I want to edit then use AIEdit.

Unfortunately, the AIEdit prompt happens in the vim command which is not as great a a vim buffer.

Would it be possible to perform AIEdit prompt directly from the AIChat buffer ?

madox2 commented 11 months ago

Hi, I am sorry but I don't understand what are you trying to accomplish. Could you be more specific?

MartinDelille commented 11 months ago

Let's say I am editing main.cpp in vim and I want to improve it. I currently need to select the whole buffer and type :'<,'>AIChat Suggest code improvement.

It then open a chat buffer and give me 3 suggestions. I ask him to apply only the two first and I then need to copy paste the generated code.

Would it be possible somehow to ask to perform the modification to the original buffer like: "Apply the 2 first code suggestion to the main.cpp buffer" directly from the chat buffer ?

madox2 commented 11 months ago

I see, in other words you are trying to edit a buffer based on the context from the chat. What could help you is to ask in chat to "Apply the 2 first code suggestions to the original code" and then copy the result and paste it to the buffer.

I can even imagine that it could be possible to implement a custom command that would somehow automatize this task. The idea of such command would be something like this: :AIEdit based on this conversation: {chat content}. Apply the 2 first code suggestions to the code: {buffer content}

MartinDelille commented 11 months ago

Thanks for answering! Regarding your command suggestion, is the {chat content} and {buffer content} something that I can do with vim ?

madox2 commented 11 months ago

I believe so. That is just to sketch out the idea, the implementation could be of course more complicated

MartinDelille commented 11 months ago

I thought other editor like https://cursor.sh/ or copilot chat handle that but in fact not. The current copy paste is kind of an issue because it can potentially change a lot of code and it might be use full to have only some small diff.

If you are ok we could let this issue open to think more on how to ask the model to propose modification to our code.