David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
992 stars 64 forks source link

Add $register variable for prompts #13

Closed leafo closed 9 months ago

leafo commented 9 months ago

This will allow you to reference the value in the unnamed (yank) register in your prompts. I made it throw an error if that value is empty, not sure if this kind of error reported is desired in the project. Feel free to change the name of the variable as well.

The idea here is that you have three sources of input:

Here's an example of how it might be used with a custom prompt I made:

https://github.com/David-Kunz/gen.nvim/assets/15198/394448c5-a248-469c-91bc-2908005fd617

Modify_With_Reference = {
  prompt = table.concat({
    "Referencing the following:",
    "$register",
    "Modify the following text, $input, just output the final text without additional quotes around it:",
    "$text",
  }, "\n"),
  replace = true
}
David-Kunz commented 9 months ago

Hey @leafo ,

Thank you, this is neat! We could also enhance it by saying $registera or $registerx etc, but for now we can leave it like that!

Best regards, David