Skip to content

maheshbansod/ai.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ace2b25 · Feb 17, 2025

History

32 Commits
Feb 17, 2025
Jan 10, 2025
Feb 16, 2025
Dec 28, 2024
Dec 28, 2024
Feb 17, 2025
Feb 16, 2025

Repository files navigation

ai.nvim

AI in neovim.

Warning

Work in progress.

Currently supports gemini.

Installation

Using lazy.nvim

-- plugins/ai.lua
return {
    'maheshbansod/ai.nvim',
    dependencies = { 'nvim-lua/plenary.nvim' },
    config = function()
      require('ai').setup({
        -- It needs an API key to access the Gemini API
        api_key_getter = function()
          -- get it from a file
          local path = vim.fn.stdpath('data') .. "/secrets/google_ai_api_key"
          local lines = vim.fn.readfile(path)
          return lines[1]
        end
      })
      -- You can set a keymap
      vim.keymap.set({ 'n', 'v' }, '<M-k>', require 'ai'.get_ai_suggestion)
    end
  }

Usage

Quick change

:AiSuggestion in normal mode or visual mode.

-> opens a floating window where one can write a prompt
-> press <enter>
-> AI content will replace the selected text

Chat

:AiChat in normal mode

-> opens a split window
-> Add your message on a line starting with User:
-> Messages go to the LLM and a response is appended to the buffer.

You can refer to a specific file in the chat as @file:<file path> . Here, the file path is relative to the root of the project. The files you include are included as part of the system prompt. To refer to the current file you can type @file:current

Future

  • Chat
    • Can be file level, selection level, or codebase level.
  • Approval system - not really sure rn how
    • maybe should also show the diff

See TODO.md

About

AI stuff in neovim

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages