avante.nvim is a Neovim plugin designed to emulate the behaviour of the Cursor AI IDE. It provides users with AI-driven code suggestions and the ability to apply these recommendations directly to their source files with minimal effort.
Note
🥰 This project is undergoing rapid iterations, and many exciting features will be added successively. Stay tuned!
avante-2.mp4
avante-3.mp4
- AI-Powered Code Assistance: Interact with AI to ask questions about your current code file and receive intelligent suggestions for improvement or modification.
- One-Click Application: Quickly apply the AI's suggested changes to your source code with a single command, streamlining the editing process and saving time.
For building binary if you wish to build from source, then cargo
is required. Otherwise curl
and tar
will be used to get prebuilt binary from GitHub.
lazy.nvim (recommended)
{
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false, -- set this if you want to always pull the latest change
opts = {
-- add any opts here
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
build = "make",
-- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
"nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
"zbirenbaum/copilot.lua", -- for providers='copilot'
{
-- support for image pasting
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
-- recommended settings
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
-- required for Windows users
use_absolute_path = true,
},
},
},
{
-- Make sure to set this up properly if you have lazy=true
'MeanderingProgrammer/render-markdown.nvim',
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
},
}
vim-plug
" Deps
Plug 'stevearc/dressing.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'MunifTanjim/nui.nvim'
" Optional deps
Plug "hrsh7th/nvim-cmp"
Plug 'nvim-tree/nvim-web-devicons' "or Plug 'echasnovski/mini.icons'
Plug 'HakonHarnes/img-clip.nvim'
Plug 'zbirenbaum/copilot.lua'
" Yay, pass source=true if you want to build from source
Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
autocmd! User avante.nvim lua << EOF
require('avante_lib').load()
require('avante').setup()
EOF
mini.deps
local add, later, now = MiniDeps.add, MiniDeps.later, MiniDeps.now
add({
source = 'yetone/avante.nvim',
monitor = 'main',
depends = {
'stevearc/dressing.nvim',
'nvim-lua/plenary.nvim',
'MunifTanjim/nui.nvim',
'echasnovski/mini.icons'
},
hooks = { post_checkout = function() vim.cmd('make') end }
})
--- optional
add({ source = 'hrsh7th/nvim-cmp' })
add({ source = 'zbirenbaum/copilot.lua' })
add({ source = 'HakonHarnes/img-clip.nvim' })
add({ source = 'MeanderingProgrammer/render-markdown.nvim' })
now(function() require('avante_lib').load() end)
later(function() require('render-markdown').setup({...}) end)
later(function()
require('img-clip').setup({...}) -- config img-clip
require("copilot").setup({...}) -- setup copilot to your liking
require("avante").setup({...}) -- config for avante.nvim
end)
Lua
-- deps:
require('cmp').setup ({
-- use recommended settings from above
})
require('img-clip').setup ({
-- use recommended settings from above
})
require('copilot').setup ({
-- use recommended settings from above
})
require('render-markdown').setup ({
-- use recommended settings from above
})
require('avante_lib').load()
require('avante').setup ({
-- Your config here!
})
NOTE: For avante.tokenizers
and templates to work, make sure to call require('avante_lib').load()
somewhere when entering the editor. We will leave the users to decide where it fits to do this, as this varies among configurations. (But we do recommend running this after where you set your colorscheme)
Important
avante.nvim
is currently only compatible with Neovim 0.10.1 or later. Please ensure that your Neovim version meets these requirements before proceeding.
Note
Recommended Neovim options:
-- views can only be fully collapsed with the global statusline
vim.opt.laststatus = 3
Tip
Any rendering plugins that support markdown should work with Avante as long as you add the supported filetype Avante
. See #175 and this comment for more information.
See config.lua#L9 for the full config
{
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
provider = "claude", -- Recommend using Claude
auto_suggestions_provider = "claude", -- Since auto-suggestions are a high-frequency operation and therefore expensive, it is recommended to specify an inexpensive provider or even a free provider: copilot
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20241022",
temperature = 0,
max_tokens = 4096,
},
---Specify the special dual_boost mode
---1. enabled: Whether to enable dual_boost mode. Default to false.
---2. first_provider: The first provider to generate response. Default to "openai".
---3. second_provider: The second provider to generate response. Default to "claude".
---4. prompt: The prompt to generate response based on the two reference outputs.
---5. timeout: Timeout in milliseconds. Default to 60000.
---How it works:
--- When dual_boost is enabled, avante will generate two responses from the first_provider and second_provider respectively. Then use the response from the first_provider as provider1_output and the response from the second_provider as provider2_output. Finally, avante will generate a response based on the prompt and the two reference outputs, with the default Provider as normal.
---Note: This is an experimental feature and may not work as expected.
dual_boost = {
enabled = false,
first_provider = "openai",
second_provider = "claude",
prompt = "Based on the two reference outputs below, generate a response that incorporates elements from both but reflects your own judgment and unique perspective. Do not provide any explanation, just give the response directly. Reference Output 1: [{{provider1_output}}], Reference Output 2: [{{provider2_output}}]",
timeout = 60000, -- Timeout in milliseconds
},
behaviour = {
auto_suggestions = false, -- Experimental stage
auto_set_highlight_group = true,
auto_set_keymaps = true,
auto_apply_diff_after_generation = false,
support_paste_from_clipboard = false,
minimize_diff = true, -- Whether to remove unchanged lines when applying a code block
},
mappings = {
--- @class AvanteConflictMappings
diff = {
ours = "co",
theirs = "ct",
all_theirs = "ca",
both = "cb",
cursor = "cc",
next = "]x",
prev = "[x",
},
suggestion = {
accept = "<M-l>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
jump = {
next = "]]",
prev = "[[",
},
submit = {
normal = "<CR>",
insert = "<C-s>",
},
sidebar = {
apply_all = "A",
apply_cursor = "a",
switch_windows = "<Tab>",
reverse_switch_windows = "<S-Tab>",
},
},
hints = { enabled = true },
windows = {
---@type "right" | "left" | "top" | "bottom"
position = "right", -- the position of the sidebar
wrap = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width
sidebar_header = {
enabled = true, -- true, false to enable/disable the header
align = "center", -- left, center, right for title
rounded = true,
},
input = {
prefix = "> ",
height = 8, -- Height of the input window in vertical layout
},
edit = {
border = "rounded",
start_insert = true, -- Start insert mode when opening the edit window
},
ask = {
floating = false, -- Open the 'AvanteAsk' prompt in a floating window
start_insert = true, -- Start insert mode when opening the ask window
border = "rounded",
---@type "ours" | "theirs"
focus_on_apply = "ours", -- which diff to focus after applying
},
},
highlights = {
---@type AvanteConflictHighlights
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
--- @class AvanteConflictUserConfig
diff = {
autojump = true,
---@type string | fun(): any
list_opener = "copen",
--- Override the 'timeoutlen' setting while hovering over a diff (see :help timeoutlen).
--- Helps to avoid entering operator-pending mode with diff mappings starting with `c`.
--- Disable by setting to -1.
override_timeoutlen = 500,
},
}
Given its early stage, avante.nvim
currently supports the following basic functionalities:
Important
Avante will only support Claude, and OpenAI (and its variants including azure)out-of-the-box due to its high code quality generation. For all OpenAI-compatible providers, see wiki for more details.
Important
Due to the poor performance of other models, avante.nvim only recommends using the claude-3.5-sonnet model. All features can only be guaranteed to work properly on the claude-3.5-sonnet model. We do not accept changes to the code or prompts to accommodate other models. Otherwise, it will greatly increase our maintenance costs. We hope everyone can understand. Thank you!
Important
For most consistency between neovim session, it is recommended to set the environment variables in your shell file.
By default, Avante
will prompt you at startup to input the API key for the provider you have selected.
For Claude:
export ANTHROPIC_API_KEY=your-api-key
For OpenAI:
export OPENAI_API_KEY=your-api-key
For Azure OpenAI:
export AZURE_OPENAI_API_KEY=your-api-key
- Open a code file in Neovim.
- Use the
:AvanteAsk
command to query the AI about the code. - Review the AI's suggestions.
- Apply the recommended changes directly to your code with a simple command or key binding.
Note: The plugin is still under active development, and both its functionality and interface are subject to significant changes. Expect some rough edges and instability as the project evolves.
The following key bindings are available for use with avante.nvim
:
Key Binding | Description |
---|---|
Leaderaa | show sidebar |
Leaderar | refresh sidebar |
Leaderaf | switch sidebar focus |
Leaderae | edit selected blocks |
co | choose ours |
ct | choose theirs |
ca | choose all theirs |
c0 | choose none |
cb | choose both |
cc | choose cursor |
]x | move to previous conflict |
[x | move to next conflict |
[[ | jump to previous codeblocks (results window) |
]] | jump to next codeblocks (results windows) |
Note
If you are using lazy.nvim
, then all keymap here will be safely set, meaning if <leader>aa
is already binded, then avante.nvim won't bind this mapping.
In this case, user will be responsible for setting up their own. See notes on keymaps for more details.
Highlight Group | Description | Notes |
---|---|---|
AvanteTitle | Title | |
AvanteReversedTitle | Used for rounded border | |
AvanteSubtitle | Selected code title | |
AvanteReversedSubtitle | Used for rounded border | |
AvanteThirdTitle | Prompt title | |
AvanteReversedThirdTitle | Used for rounded border | |
AvanteConflictCurrent | Current conflict highlight | Default to Config.highlights.diff.current |
AvanteConflictIncoming | Incoming conflict highlight | Default to Config.highlights.diff.incoming |
AvanteConflictCurrentLabel | Current conflict label highlight | Default to shade of AvanteConflictCurrent |
AvanteConflictIncomingLabel | Incoming conflict label highlight | Default to shade of AvanteConflictIncoming |
AvantePopupHint | Usage hints in popup menus | |
AvanteInlineHint | The end-of-line hint displayed in visual mode |
See highlights.lua for more information
By default, avante.nvim
provides three different modes to interact with: planning
, editing
, and suggesting
, followed with three different prompts per mode.
planning
: Used withrequire("avante").toggle()
on sidebarediting
: Used withrequire("avante").edit()
on selection codeblocksuggesting
: Used withrequire("avante").get_suggestion():suggest()
on Tab flow.
Users can customize the system prompts via Config.system_prompt
. We recommend calling this in a custom Autocmds depending on your need:
vim.api.nvim_create_autocmd("User", {
pattern = "ToggleMyPrompt",
callback = function() require("avante.config").override({system_prompt = "MY CUSTOM SYSTEM PROMPT"}) end,
})
vim.keymap.set("n", "<leader>am", function() vim.api.nvim_exec_autocmds("User", { pattern = "ToggleMyPrompt" }) end, { desc = "avante: toggle my prompt" })
If one wish to custom prompts for each mode, avante.nvim
will check for project root based on the given buffer whether it contains
the following patterns: *.{mode}.avanterules
.
The rules for root hierarchy:
- lsp workspace folders
- lsp root_dir
- root pattern of filename of the current buffer
- root pattern of cwd
Example folder structure for custom prompt
If you have the following structure:
.
├── .git/
├── typescript.planning.avanterules
├── snippets.editing.avanterules
└── src/
typescript.planning.avanterules
will be used forplanning
modesnippets.editing.avanterules`` will be used for
editing` mode- the default
suggesting
prompt fromavante.nvim
will be used forsuggesting
mode.
Important
*.avanterules
is a jinja template file, in which will be rendered using minijinja. See templates for example on how to extend current templates.
- Chat with current file
- Apply diff patch
- Chat with the selected block
- Slash commands
- Edit the selected block
- Smart Tab (Cursor Flow)
- Chat with project (You can use
@codebase
to chat with the whole project) - CoT
- Chat with selected files
- Enhanced AI Interactions: Improve the depth of AI analysis and recommendations for more complex coding scenarios.
- LSP + Tree-sitter + LLM Integration: Integrate with LSP and Tree-sitter and LLM to provide more accurate and powerful code suggestions and analysis.
Contributions to avante.nvim are welcome! If you're interested in helping out, please feel free to submit pull requests or open issues. Before contributing, ensure that your code has been thoroughly tested.
See wiki for more recipes and tricks.
We would like to express our heartfelt gratitude to the contributors of the following open-source projects, whose code has provided invaluable inspiration and reference for the development of avante.nvim:
Nvim Plugin | License | Functionality | Location |
---|---|---|---|
git-conflict.nvim | No License | Diff comparison functionality | lua/avante/diff.lua |
ChatGPT.nvim | Apache 2.0 License | Calculation of tokens count | lua/avante/utils/tokens.lua |
img-clip.nvim | MIT License | Clipboard image support | lua/avante/clipboard.lua |
copilot.lua | MIT License | Copilot support | lua/avante/providers/copilot.lua |
jinja.vim | MIT License | Template filetype support | syntax/jinja.vim |
codecompanion.nvim | MIT License | Secrets logic support | lua/avante/providers/init.lua |
aider | Apache 2.0 License | Planning mode user prompt | lua/avante/templates/planning.avanterules |
The high quality and ingenuity of these projects' source code have been immensely beneficial throughout our development process. We extend our sincere thanks and respect to the authors and contributors of these projects. It is the selfless dedication of the open-source community that drives projects like avante.nvim forward.
avante.nvim is licensed under the Apache 2.0 License. For more details, please refer to the LICENSE file.