gemini.nvim icon indicating copy to clipboard operation
gemini.nvim copied to clipboard

Keybindings, usage examples

Open ptman opened this issue 10 months ago • 9 comments

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 avatar Mar 06 '25 11:03 ptman

@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...)

rakotomandimby avatar Mar 06 '25 11:03 rakotomandimby

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.

kiddos avatar Mar 06 '25 15:03 kiddos

GeminiTask seems to work. GeminiApply doesn't. And keybindings aren't listed

ptman avatar Mar 06 '25 20:03 ptman

I tried a different way to prompt it. It works a bit better now.

kiddos avatar Apr 05 '25 18:04 kiddos

this seems pretty cool but I cant figure out the keybindings!

fionnafire avatar May 12 '25 02:05 fionnafire

I added some docs: doc/gemini.nvim.txt hope this would help.

kiddos avatar May 17 '25 12:05 kiddos

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.

kiddos avatar May 17 '25 12:05 kiddos

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.

mcepl avatar Aug 06 '25 07:08 mcepl

yeah, currently :GeminiTask can only input single line text. It will need a multiline UI to prompt long text to it.

kiddos avatar Aug 07 '25 02:08 kiddos