Skip to content

marcinjahn/gemini-cli.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

gemini-cli.nvim

๐Ÿค– Seamlessly integrate GeminiCLI with Neovim for an enhanced AI-assisted coding experience!

๐ŸŒŸ Features

  • ๐Ÿ–ฅ๏ธ Gemini CLI terminal integration within Neovim
  • ๐Ÿ“ค Quick commands to add current buffer files (using @ syntax)
  • ๐Ÿฉบ Send current buffer diagnostics to Gemini CLI
  • ๐Ÿ” Gemini CLI command selection UI with fuzzy search and input prompt
  • ๐Ÿ”Œ Fully documented Lua API for programmatic interaction and custom integrations
  • ๐Ÿ”„ Auto-reload buffers on external changes (requires 'autoread')

๐ŸŽฎ Commands

  • :Gemini - Open interactive command menu

    Commands:
    health         ๐Ÿฉบ Check plugin health status
    toggle         ๐ŸŽ›๏ธ Toggle GeminiCLI terminal window
    command        โŒจ๏ธ Show slash commands
     > diagnostics ๐Ÿฉบ Send current buffer diagnostics
    add_file       โž• Add current file to session (using `@` syntax)
    ask            โ“ Ask a question
    
  • โšก Direct command execution examples:

    :Gemini health
    :Gemini add_file
    :Gemini send "Fix login validation"

๐Ÿ”— Requirements

๐Ÿ Python: Install gemini-cli ๐Ÿ“‹ System: Neovim >= 0.9.4 ๐ŸŒ™ Lua: folke/snacks.nvim,

๐Ÿ“ฆ Installation

Using lazy.nvim:

{
    "marcinjahn/gemini-cli.nvim",
    cmd = "Gemini",
    -- Example key mappings for common actions:
    keys = {
      { "<leader>a/", "<cmd>Gemini toggle<cr>", desc = "Toggle Gemini CLI" },
      { "<leader>aa", "<cmd>Gemini ask<cr>", desc = "Ask Gemini", mode = { "n", "v" } },
      { "<leader>af", "<cmd>Gemini add_file<cr>", desc = "Add File" },

    },
    dependencies = {
      "folke/snacks.nvim",
    },
    config = true,
  }

After installing, run :GeminiCLI health to check if everything is set up correctly.

โš™๏ธ Configuration

There is no need to call setup if you don't want to change the default options.

require("gemini_cli").setup({
  -- Command that executes GeminiCLI
  gemini_cmd = "gemini",
  -- Command line arguments passed to gemini-cli
  args = {
  },
  -- Automatically reload buffers changed by GeminiCLI (requires vim.o.autoread = true)
  auto_reload = false,
  -- snacks.picker.layout.Config configuration
  picker_cfg = {
    preset = "vscode",
  },
  -- Other snacks.terminal.Opts options
  config = {
    os = { editPreset = "nvim-remote" },
    gui = { nerdFontsVersion = "3" },
  },
  win = {
    wo = { winbar = "GeminiCLI" },
    style = "gemini_cli",
    position = "right",
  },
})

๐Ÿ“š API Reference

The plugin provides a structured API for programmatic integration. Access via require("gemini_cli").api

Core Functions

local api = require("gemini_cli").api

health_check()

Verify plugin health status

api.health_check()

toggle_terminal(opts?)

Toggle GeminiCLI terminal window

api.toggle_terminal()

Terminal Operations

send_to_terminal(text, opts?)

Send raw text directly to GeminiCLI

api.send_to_terminal("Fix the login validation")

send_command(command, input?, opts?)

Execute specific GeminiCLI command

api.send_command("/commit", "Add error handling")

File Management

add_file(filepath)

Add specific file to session

api.add_file("/src/utils.lua")

``

add_current_file()

Add current buffer's file (uses add_file internally)

vim.api.nvim_create_autocmd("BufWritePost", {
  callback = function()
    api.add_current_file()
  end
})

send_diagnostics_with_prompt(opts?)

Send current buffer's diagnostics with an optional prompt

api.send_diagnostics_with_prompt()

UI Components

open_command_picker(opts?, callback?)

Interactive command selector with custom handling

api.open_command_picker(nil, function(picker, item)
  if item.text == "/custom" then
    -- Implement custom command handling
  else
    -- Default behavior
    picker:close()
    api.send_command(item.text)
  end
end)

This plugin is a Gemini CLI adaptation of nvim-aider.

About

Seamlessly integrate Gemini CLI with Neovim for an enhanced AI-assisted coding experience!

Topics

Resources

License

Stars

Watchers

Forks

Contributors