https://github.com/zaucy/gemini.nvim
gemini cli integration for neovim
https://github.com/zaucy/gemini.nvim
gemini-cli mcp mcp-server neovim neovim-plugin
Last synced: 6 months ago
JSON representation
gemini cli integration for neovim
- Host: GitHub
- URL: https://github.com/zaucy/gemini.nvim
- Owner: zaucy
- License: mit
- Created: 2026-01-19T00:32:36.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-01-19T04:52:43.000Z (6 months ago)
- Last Synced: 2026-01-19T13:35:49.130Z (6 months ago)
- Topics: gemini-cli, mcp, mcp-server, neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gemini.nvim
Neovim support for the Gemini CLI, featuring a built-in diff viewer and hook support. This plugin doesn't actually spawn Gemini; it just sets up environment variables and workspace settings so that when you run Gemini, it can communicate with Neovim.
Note that you should use [zaucy/mcp.nvim](https://github.com/zaucy/mcp.nvim) to register tools and prompts; this plugin focuses specifically on the Gemini IDE integration and listening for hooks.
## Installation
### [lazy.nvim](https://github.com/folke/lazy.nvim)
```lua
{
"zaucy/gemini.nvim",
dependencies = {
"zaucy/mcp.nvim",
},
opts = {},
}
```
## Autocommands
This plugin exposes several user autocommands that you can use to trigger actions during various stages of the Gemini interaction.
| Pattern | Description | Data |
| :--- | :--- | :--- |
| `GeminiHookSessionStart` | Triggered when a new Gemini session starts. | `context` |
| `GeminiHookBeforeAgent` | Triggered before the agent begins processing. | `context` |
| `GeminiHookBeforeToolSelection` | Triggered before the model selects a tool. | `context` |
| `GeminiHookBeforeTool` | Triggered before a tool is executed. | `context` |
| `GeminiHookAfterTool` | Triggered after a tool has been executed. | `context` |
| `GeminiHookAfterModel` | Triggered after the model completes its response. | `context` |
| `GeminiHookSessionEnd` | Triggered when the Gemini session ends. | `context` |
| `GeminiOpenDiffPre` | Triggered before a diff view is opened. | - |
| `GeminiOpenDiff` | Triggered after a diff view is opened. | `bufnr` |
| `GeminiCloseDiff` | Triggered after a diff view is closed. | `bufnr` |
### Example Usage
```lua
vim.api.nvim_create_autocmd("User", {
pattern = "GeminiHookAfterTool",
callback = function(args)
local context = args.data.context
-- Example: Print tool name if available in context
if context.tool_name then
print("Tool executed: " .. context.tool_name)
end
end,
})
```
## Implementation Strategy
`gemini.nvim` integrates closely with [mcp.nvim](https://github.com/zaucy/mcp.nvim) to provide a seamless environment for the Gemini CLI.
The implementation relies on several key mechanisms:
1. **Event-Driven Configuration:** The plugin listens for `McpServerCreated` and `McpServerDirChange` autocommands from `mcp.nvim`. When these events occur, `gemini.nvim` dynamically generates settings for the current workspace.
2. **Environment Variables:** Upon a directory change within an MCP-enabled project, the plugin updates specific environment variables:
- `GEMINI_CLI_IDE_WORKSPACE_PATH`: The current project root.
- `GEMINI_CLI_SYSTEM_SETTINGS_PATH`: Path to a workspace-specific `settings.json` file generated by the plugin.
- `GEMINI_CLI_IDE_SERVER_STDIO_COMMAND` & `GEMINI_CLI_IDE_SERVER_STDIO_ARGS`: Configures Gemini to communicate back to Neovim as an MCP server using a specialized client script.
3. **Dynamic Settings Generation:** The plugin generates a `settings.json` file that:
- Configures Neovim as an MCP server for Gemini, enabling it to call tools like `openDiff` and `closeDiff`.
- Sets up "Hooks" that notify Neovim about session events (e.g., `BeforeTool`, `AfterModel`).
4. **Hook System:** When Gemini executes hooks, it calls a hook script provided by this plugin, which in turn communicates with Neovim via RPC to trigger `User` autocommands, allowing for extensible behavior.
## Other plugins
* https://github.com/vaijab/gemini-cli.nvim - original inspiration for this plugin