Skip to content
forked from simo5/vimini

Vim plugin to use Gemini APIs as a code assistant

License

Notifications You must be signed in to change notification settings

rjeffman/vimini

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vimini: Google Gemini Integration for Vim

Vimini is a Vim plugin that provides seamless integration with Google's Gemini (Generative AI) models, allowing you to interact with AI directly from your Vim editor. You can chat, generate code, list available models, and get code reviews without leaving your coding environment.

Features

  • Chat with Gemini: Send prompts and receive responses in a new buffer.
  • Context-Aware Code Generation: Use all open buffers as context to generate code.
  • Code Review: Get AI-powered reviews for the code in your current buffer or from your git history.
  • Git Integration: Generate commit messages and view diffs using AI.
  • List Models: Easily view all available Gemini models.
  • API Key Management: Configure your Gemini API key securely.
  • Live "Thinking" View: Optionally watch the AI's thought process in real-time during code generation.

Requirements

  • Vim (or Neovim) with Python 3 support.
  • Python 3.6+
  • The google-genai Python library. You can install it via pip:
    pip install google-genai
  • git must be installed and in your PATH for the Git-related commands.

Installation

You can install Vimini using your preferred Vim plugin manager.

Using Vim-Plug:

  1. Add the following line to your .vimrc or init.vim:
    call plug#begin()
    Plug 'your-github-username/vimini.vim' " Replace with the actual repo path
    call plug#end()
  2. Run :PlugInstall in Vim.

Using Packer.nvim:

  1. Add the following to your init.lua (for Neovim) or plugins.lua:
    use 'your-github-username/vimini.nvim' " Replace with the actual repo path
  2. Run :PackerSync or :PackerInstall in Neovim.

(Note: Replace your-github-username/vimini.vim with the actual repository path once published.)

Configuration

Vimini requires your Google Gemini API key and a default model to function.

  1. API Key (g:vimini_api_key): You can set your API key directly in your .vimrc or init.vim:

    let g:vimini_api_key = 'YOUR_API_KEY_HERE'

    Alternatively, Vimini will also look for the API key in a file named ~/.config/gemini.token. This is the recommended and more secure approach. Just place your API key (and nothing else) into that file:

    # ~/.config/gemini.token
    YOUR_API_KEY_HERE
    
  2. Default Model (g:vimini_model): Specify the default Gemini model you want to use. The default is gemini-2.5-flash. You can list available models using :ViminiListModels.

    let g:vimini_model = 'gemini-2.5-flash' " Or 'gemini-2.5-pro', etc.
  3. Thinking Display (g:vimini_thinking): Control whether the AI's "thinking" process is displayed in a separate buffer during code generation.

    " Show the 'Vimini Thoughts' buffer. (Default)
    let g:vimini_thinking = 'on'
    
    " Hide the 'Vimini Thoughts' buffer.
    let g:vimini_thinking = 'off'

    This can also be controlled with the :ViminiThinking command.

Usage

Vimini exposes several commands for interacting with the Gemini API:

:ViminiListModels

Lists all available Gemini models in a new split window. This is useful for knowing which models you can set for g:vimini_model.

:ViminiListModels

:ViminiChat {prompt}

Sends a prompt to the configured Gemini model and displays the AI's response in a new vertical split buffer.

:ViminiChat What is the capital of France?

:ViminiThinking [on|off]

Toggles or sets the display of the AI's real-time thought process during code generation. When enabled, a Vimini Thoughts buffer will appear alongside the Vimini Code buffer.

" Toggle the current setting (on -> off, off -> on)
:ViminiThinking

" Explicitly turn the thinking display on
:ViminiThinking on

" Explicitly turn the thinking display off
:ViminiThinking off

:ViminiCode {prompt}

Takes the content of all open buffers as context, along with your prompt, and asks the Gemini model to generate code. The result is streamed into several new buffers:

  • Vimini Code: The generated code.
  • Vimini Diff: A diff view comparing the original code with the AI's suggestion.
  • Vimini Thoughts (Optional): If g:vimini_thinking is on (the default), this buffer shows the AI's internal monologue as it works.

This command is ideal for asking the AI to refactor, debug, or extend your current code.

:ViminiCode Please refactor this function to be more concise

After running :ViminiCode, you can use one of the following commands to apply the changes:

:ViminiApply

Replaces the entire content of your original buffer with the AI-generated code from the Vimini Code buffer. It then closes the temporary Vimini Code, Vimini Diff, and Vimini Thoughts buffers.

:ViminiApply append

Appends the AI-generated code to the end of your original buffer. This is useful when you've asked the AI to add a new function or class. It also closes the temporary Vimini Code, Vimini Diff, and Vimini Thoughts buffers.

:ViminiReview [C:<git_objects>] [{prompt}]

Sends content to the Gemini model for a code review. This command has two modes:

  1. Current Buffer Review: If no git_objects are provided, it sends the content of the current buffer for review.
  2. Git Object Review: If the command starts with C:<git_objects>, it reviews the output of git show <git_objects>. <git_objects> can be any valid git object reference, like a commit hash, branch name, or HEAD~1.

In both cases, you can add an optional {prompt} to guide the AI's review. The review and suggestions will be displayed in a new vertical split buffer.

Examples:

" Review the current buffer for performance issues
:ViminiReview Check for performance issues.

" Perform a general review of the current buffer
:ViminiReview

" Review the changes in the latest commit
:ViminiReview C:HEAD

" Review changes from two commits ago and ask for security vulnerabilities
:ViminiReview C:HEAD~2 "Check for security vulnerabilities"

Git Integration

Vimini offers commands to integrate with your Git workflow.

:ViminiDiff

Shows the output of git diff for the current repository in a new split window. This allows you to see unstaged changes without leaving Vim.

:ViminiDiff

:ViminiCommit

Automates the commit process using AI. This command:

  1. Stages all current changes (git add .).
  2. Generates a conventional commit message (subject and body) based on the staged diff.
  3. Displays the generated message in a popup for you to confirm (y) or cancel (n).
  4. If confirmed, it commits the changes with the generated message and a Co-authored-by: Gemini trailer.
:ViminiCommit

Sheperd's note

Most of the code here is generated by Gemini itself, I only provide guidance and occasioanly edit some small bit where it is easier then asking

Also, it's important to remember that AI, much like a well-fed cat, requires a steady stream of attention and high-quality prompts to perform its best tricks. Neglect it, and you might just find it napping on your keyboard when you need it most. -- Simo.

About

Vim plugin to use Gemini APIs as a code assistant

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 81.5%
  • Vim Script 18.5%