Keybindings, usage examples
Now with free gemini ( https://blog.google/technology/developers/gemini-code-assist-free/ ) this is quite an interesting vim plugin. Does it use the free gemini code assist or something else?
For me the videos don't really explain how to use this plugin.
:GeminiChat doesn't seem to use the current file as context. Or at least it generates python code for me in a golang file.
@ptman ,
The free Gemini code assist does not seem to be available via API.
It is only available as an extension or plugin for Visual Studio Code and JetBrains IDEs,
I guess in order to have it for Neovim, someone has to reverse engineer those plugin (If it is even legal...)
I added :GeminiTask command recently. It uses the opened buffers as current context. I made it so that it outputs git diff.
You can try to customize it with the settings:
task = {
enabled = true,
get_system_text = function()
return 'You are an AI assistant that helps user write code.\n'
.. 'Your output should be a code diff for git.'
end,
get_prompt = function(bufnr, user_prompt)
local buffers = vim.api.nvim_list_bufs()
local file_contents = {}
for _, b in ipairs(buffers) do
if vim.api.nvim_buf_is_loaded(b) then -- Only get content from loaded buffers
local lines = vim.api.nvim_buf_get_lines(b, 0, -1, false)
local filename = vim.api.nvim_buf_get_name(b)
filename = vim.fn.fnamemodify(filename, ":.")
local filetype = vim.api.nvim_get_option_value('filetype', { buf = b })
local file_content = table.concat(lines, "\n")
file_content = string.format("`%s`:\n\n```%s\n%s\n```\n\n", filename, filetype, file_content)
table.insert(file_contents, file_content)
end
end
local current_filepath = vim.api.nvim_buf_get_name(bufnr)
current_filepath = vim.fn.fnamemodify(current_filepath, ":.")
local context = table.concat(file_contents, "\n\n")
return string.format('%s\n\nCurrent Opened File: %s\n\nTask: %s',
context, current_filepath, user_prompt)
end
},
It doesn't really work sometimes 🤕 .
The VSCode video in the link seems to work pretty well. I could try to prompt it to modify the original code and extract code block.
GeminiTask seems to work. GeminiApply doesn't. And keybindings aren't listed
I tried a different way to prompt it. It works a bit better now.
this seems pretty cool but I cant figure out the keybindings!
I added some docs: doc/gemini.nvim.txt hope this would help.
for :GeminiTask, you could sort of change the get_prompt function, and put the entire codebase (maybe just files with the same extension) into gemini, since it's got really large context window.
How to make a multiline prompt? It really doesn’t help, that I don’t seem to have a way how to send a backtrace to Gemini.
yeah, currently :GeminiTask can only input single line text. It will need a multiline UI to prompt long text to it.