# neovim-gemini

A Neovim plugin for interacting with the Google AI API (formerly Gemini). Get AI-powered assistance directly within your Neovim editor.

## Requirements

* Neovim 0.8 or higher
* A Google AI API key (obtainable from [https://makersuite.google.com/app/apikey](https://makersuite.google.com/app/apikey))
* `curl` installed on your system
* Treesitter installed with the markdown parser (automatically installed during setup)

## Installation

Use your favorite Neovim package manager. Here's how to install with Lazy.nvim:

```lua
{
  "your_username/neovim-gemini",
  config = function()
    require("gemini").setup()
  end,
}
```

## Configuration

Set your API key using one of these methods:

1. Environment variable:
```bash
export GEMINI_API_KEY="your-api-key-here"
```

2. Neovim configuration:
```lua
-- In your init.lua
vim.g.gemini_api_key = "your-api-key-here"
```

## Usage

The plugin provides several ways to interact with Gemini:

1. Command Mode:
```vim
:Gemini What is SOLID in software engineering?
```

2. Simple Query:
- Press `<leader>gc` to open an input prompt (mnemonic: 'gemini chat')
- Type your query and press Enter

3. Context-Aware Query:
- Press `<leader>gs` to open an input prompt (mnemonic: 'gemini sync')
- This will send your current buffer's content as context along with your query
- Useful for code-related questions about the file you're working on

4. Clear Chat History:
- Press `<leader>gq` to clear the chat history (mnemonic: 'gemini quit')
- This will clear both the chat window and conversation history
- You can also use the `:GeminiClearChat` command

### Chat Window Controls

The chat window appears on the right side of your editor and provides the following controls:

- `i`: Enter a new query
  - If the chat was started with buffer context (using `<leader>gs`), subsequent queries will maintain that context
  - If started without context (using `<leader>gc`), queries will be context-free
- `q`: Close the chat window (history is preserved)
- `<Esc>`: Return focus to previous buffer
- Normal mode scrolling commands (`j`, `k`, `<C-d>`, `<C-u>`, etc.) work as expected
- Window automatically scrolls to show new messages at the top

File operations in the chat window are intentionally disabled:
- `:w`, `:e`, `:sp`, `:vs` and similar commands are blocked
- The command-line mode (`:`) is disabled to prevent file operations
- A warning message appears if you attempt these operations

### Chat Commands

- `:GeminiClearChat`: Clear the conversation history and chat window
- `:Gemini <query>`: Send a query directly from command mode

## Features

- Floating window interface with persistent chat history
- Non-blocking API calls
- Error handling and notifications
- Easy-to-use command and keymap interface
- Support for the latest Gemini 2.0 Flash model
- Markdown syntax highlighting for responses
- Context-aware queries using current buffer content
- Automatic scrolling to new messages
- Protected chat window to prevent accidental modifications

## Troubleshooting

If you encounter issues:

1. Verify your API key is correctly set:
```lua
:lua print(vim.g.gemini_api_key)
```

2. Check if curl is installed:
```bash
curl --version
```

3. Ensure you have billing set up in your Google Cloud project

## License

This project is licensed under the ISC License. See the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.