My workflow is to use CLI-based code generation AI assistants. I don't need anything complicated, just select code: explain, refactor, fix or comment. This plugin does just that.
- Multiple AI provider support (OpenRouter, OpenAI, Anthropic)
- Visual mode code selection
- AI-powered code actions:
- Explain: Get detailed explanations
- Refactor: Improve code structure
- Fix: Identify and fix issues
- Comment: Generate appropriate comments
- Keyboard-driven workflow
- Non-intrusive floating window UI
- Neovim 0.7.0+
- plenary.nvim (for HTTP requests)
- API key for one of:
- OpenRouter (
OPENROUTER_API_KEY) - OpenAI (
OPENAI_API_KEY) - Anthropic (
ANTHROPIC_API_KEY)
- OpenRouter (
Using lazy.nvim
{
"avastmick/simple-ai-assist.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = function()
require("simple-ai-assist").setup({
-- Optional configuration
})
end,
keys = {
{ "<leader>ac", mode = "v", desc = "AI Code Assistant" },
},
}Using packer.nvim
use {
"avastmick/simple-ai-assist.nvim",
requires = { "nvim-lua/plenary.nvim" },
config = function()
require("simple-ai-assist").setup()
end
}require("simple-ai-assist").setup({
-- API configuration (defaults to OPENROUTER_API_KEY)
api_key = vim.env.OPENROUTER_API_KEY,
endpoint = "https://openrouter.ai/api/v1",
model = "anthropic/claude-sonnet-4",
-- Keymappings
keymaps = {
trigger = "<leader>ac", -- Trigger assistant in visual mode
accept = "C-u", -- Accept (update) AI suggestion
retry = "C-r", -- Retry same action
cancel = "<Esc>", -- Cancel and close
},
-- Window appearance
window = {
width = 0.7, -- 70% of editor width
height = 0.7, -- 70% of editor height
border = "rounded",
},
-- Available AI actions
actions = {
{ key = "<C-e>", label = "Explain", prompt = "Explain this code in detail:" },
{ key = "<C-p>", label = "Refactor", prompt = "Suggest improvements for this code:" },
{ key = "<C-f>", label = "Fix", prompt = "Find and fix issues in this code:" },
{ key = "<C-c>", label = "Comment", prompt = "Add appropriate comments to this code:" },
}
})Set your API key as an environment variable:
# For OpenRouter (default)
export OPENROUTER_API_KEY="your-key-here"
# For OpenAI
export OPENAI_API_KEY="your-key-here"
# For Anthropic
export ANTHROPIC_API_KEY="your-key-here"Add to your shell configuration file (~/.bashrc, ~/.zshrc, etc.) to persist.
- Select code in visual mode (
v,V, or<C-v>) - Press
<leader>ac(default) to trigger the assistant - Choose an action:
C-e- Explain the codeC-p- Refactor suggestionsC-f- Fix issuesC-c- Add comments
- Wait for AI response
- Then:
C-u- Accept and apply changesC-r- Retry for different response<Esc>- Cancel without changes
For local testing in your Neovim configuration:
-- In your init.lua or plugin configuration
use {
dir = "~/repos/simple-ai-assist.nvim", -- Path to local clone
requires = { "nvim-lua/plenary.nvim" },
config = function()
require("simple-ai-assist").setup()
end
}Ensure your API key environment variable is set and exported. Check with:
echo $OPENROUTER_API_KEY- Verify your internet connection
- Check API key validity
- Ensure the selected model is available for your API provider
Install plenary.nvim first:
:Lazy install nvim-lua/plenary.nvimMIT License - see LICENSE for details
Contributions are welcome! Please feel free to submit a Pull Request.