2024-08-15 04:08:18 +08:00
# avante.nvim (Alpha)
2024-08-12 23:53:28 +08:00
2024-08-15 04:11:10 +08:00
**avante.nvim** is a Neovim plugin designed to emulate the behavior of the [Cursor ](https://www.cursor.com ) AI IDE, providing users with AI-driven code suggestions and the ability to apply these recommendations directly to their source files with minimal effort.
2024-08-12 23:53:28 +08:00
2024-08-15 14:38:11 +08:00
> [!NOTE]
2024-08-17 16:04:40 -04:00
>
2024-08-18 01:47:51 +08:00
> ⚠️ This plugin is still in a very early stage of development, so please be aware that the current code is very messy and unstable, and problems are likely to occur.
2024-08-17 16:04:40 -04:00
>
2024-08-18 01:47:51 +08:00
> 🥰 This project is undergoing rapid iterations, and many exciting features will be added successively. Stay tuned!
2024-08-15 02:55:22 +08:00
https://github.com/user-attachments/assets/510e6270-b6cf-459d-9a2f-15b397d1fe53
2024-08-15 20:20:22 +08:00
https://github.com/user-attachments/assets/86140bfd-08b4-483d-a887-1b701d9e37dd
2024-08-12 23:53:28 +08:00
## Features
- **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.
## Installation
2024-08-15 08:59:01 -04:00
Install `avante.nvim` using [lazy.nvim ](https://github.com/folke/lazy.nvim ):
2024-08-15 14:38:11 +08:00
2024-08-17 15:14:30 +08:00
```lua
{
"yetone/avante.nvim",
event = "VeryLazy",
build = "make",
2024-08-18 06:07:29 -04:00
opts = {
-- add any opts here
},
2024-08-17 15:14:30 +08:00
dependencies = {
"nvim-tree/nvim-web-devicons",
2024-08-18 06:07:29 -04:00
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
2024-08-21 22:10:49 +08:00
"MunifTanjim/nui.nvim",
2024-08-18 06:07:29 -04:00
--- The below is optional, make sure to setup it properly if you have lazy=true
{
2024-08-17 22:33:40 +08:00
'MeanderingProgrammer/render-markdown.nvim',
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
2024-08-17 15:14:30 +08:00
},
}
```
2024-08-15 14:38:11 +08:00
2024-08-21 21:59:13 +08:00
For Windows users, change the build command to the following:
```lua
{
"yetone/avante.nvim",
event = "VeryLazy",
build = "powershell -ExecutionPolicy Bypass -File Build-LuaTiktoken.ps1",
-- rest of the config
}
```
2024-08-18 06:28:11 -04:00
> [!IMPORTANT]
>
> `avante.nvim` is currently only compatible with Neovim 0.10.0 or later. Please ensure that your Neovim version meets these requirements before proceeding.
2024-08-15 08:59:01 -04:00
> [!IMPORTANT]
>
> If your neovim doesn't use LuaJIT, then change `build` to `make lua51`. By default running make will install luajit.
> For ARM-based setup, make sure to also install cargo as we will have to build the tiktoken_core from source.
2024-08-21 22:31:56 +08:00
> [!NOTE]
>
> Recommended **Neovim** options:
>
> ```lua
> -- views can only be fully collapsed with the global statusline
> vim.opt.laststatus = 3
> -- Default splitting will cause your main splits to jump when opening an edgebar.
> -- To prevent this, set `splitkeep` to either `screen` or `topline`.
> vim.opt.splitkeep = "screen"
> ```
2024-08-18 01:58:08 +08:00
> [!NOTE]
2024-08-17 15:14:30 +08:00
>
> `render-markdown.nvim` is an optional dependency that is used to render the markdown content of the chat history. Make sure to also include `Avante` as a filetype
> to its setup:
>
> ```lua
> {
2024-08-17 22:33:40 +08:00
> "MeanderingProgrammer/render-markdown.nvim",
2024-08-17 15:14:30 +08:00
> opts = {
> file_types = { "markdown", "Avante" },
> },
> ft = { "markdown", "Avante" },
> }
> ```
2024-08-15 08:59:01 -04:00
Default setup configuration:
2024-08-15 14:38:11 +08:00
2024-08-17 16:04:40 -04:00
_See [config.lua#L9 ](./lua/avante/config.lua ) for the full config_
2024-08-17 15:14:30 +08:00
```lua
{
2024-08-23 00:21:30 -04:00
---@alias Provider "openai" | "claude" | "azure" | "copilot" | [string]
2024-08-19 06:11:02 -04:00
provider = "claude",
2024-08-17 15:14:30 +08:00
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20240620",
temperature = 0,
max_tokens = 4096,
},
mappings = {
2024-08-17 22:29:05 +08:00
ask = "< leader > aa",
2024-08-17 16:04:40 -04:00
edit = "< leader > ae",
refresh = "< leader > ar",
--- @class AvanteConflictMappings
2024-08-17 15:14:30 +08:00
diff = {
ours = "co",
theirs = "ct",
none = "c0",
both = "cb",
next = "]x",
prev = "[x",
2024-08-15 21:04:06 +08:00
},
2024-08-17 16:04:40 -04:00
jump = {
next = "]]",
prev = "[[",
},
},
2024-08-19 06:11:02 -04:00
hints = { enabled = true },
2024-08-17 16:04:40 -04:00
windows = {
2024-08-22 01:48:40 -04:00
wrap = true, -- similar to vim.o.wrap
2024-08-17 16:04:40 -04:00
width = 30, -- default % based on available width
2024-08-21 23:33:54 +08:00
sidebar_header = {
align = "center", -- left, center, right for title
rounded = true,
},
2024-08-17 16:04:40 -04:00
},
2024-08-20 01:57:24 +08:00
highlights = {
---@type AvanteConflictHighlights
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
2024-08-17 16:04:40 -04:00
--- @class AvanteConflictUserConfig
diff = {
debug = false,
autojump = true,
---@type string | fun(): any
list_opener = "copen",
2024-08-17 15:14:30 +08:00
},
}
```
2024-08-15 04:04:04 +08:00
2024-08-12 23:53:28 +08:00
## Usage
Given its early stage, `avante.nvim` currently supports the following basic functionalities:
2024-08-23 00:21:30 -04:00
> [!IMPORTANT]
>
> Avante will only support OpenAI (and its variants including copilot and azure), and Claude out-of-the-box due to its high code quality generation.
> For all OpenAI-compatible providers, see [wiki](https://github.com/yetone/avante.nvim/wiki) for more details.
2024-08-17 16:04:40 -04:00
> [!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:
>
> ```sh
> export ANTHROPIC_API_KEY=your-api-key
> ```
>
> For OpenAI:
>
> ```sh
> export OPENAI_API_KEY=your-api-key
> ```
>
> For Azure OpenAI:
>
> ```sh
> export AZURE_OPENAI_API_KEY=your-api-key
> ```
2024-08-15 13:44:25 +08:00
2024-08-17 16:04:40 -04:00
1. Open a code file in Neovim.
2. Use the `:AvanteAsk` command to query the AI about the code.
3. Review the AI's suggestions.
4. Apply the recommended changes directly to your code with a simple command or key binding.
2024-08-12 23:53:28 +08:00
**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.
## Key Bindings
The following key bindings are available for use with `avante.nvim` :
2024-08-15 14:18:25 +08:00
- < kbd > Leader</ kbd >< kbd > a</ kbd >< kbd > a</ kbd > — show sidebar
2024-08-17 16:04:40 -04:00
- < kbd > Leader</ kbd >< kbd > a</ kbd >< kbd > r</ kbd > — show sidebar
2024-08-15 14:18:25 +08:00
- < kbd > c</ kbd >< kbd > o</ kbd > — choose ours
- < kbd > c</ kbd >< kbd > t</ kbd > — choose theirs
- < kbd > c</ kbd >< kbd > b</ kbd > — choose both
- < kbd > c</ kbd >< kbd > 0</ kbd > — choose none
- < kbd > ]</ kbd >< kbd > x</ kbd > — move to previous conflict
- < kbd > [</ kbd >< kbd > x</ kbd > — move to next conflict
2024-08-12 23:53:28 +08:00
## Roadmap
- **Enhanced AI Interactions**: Improve the depth of AI analysis and recommendations for more complex coding scenarios.
- **Stability Improvements**: Refactor and optimize the codebase to enhance the stability and reliability of the plugin.
- **Expanded Features**: Introduce additional customization options and new features to support a wider range of coding tasks.
2024-08-24 20:15:45 -04:00
## Highlight Groups
| Highlight Group | Description |
|-----------------|-------------|
| AvanteTitle | Title |
| AvanteReversedTitle | Used for rounded border |
| AvanteSubtitle | Selected code title |
| AvanteReversedSubtitle | Used for rounded border |
| AvanteThirdTitle | Prompt title |
| AvanteReversedThirdTitle | Used for rounded border |
2024-08-15 04:11:10 +08:00
## TODOs
- [x] Chat with current file
- [x] Apply diff patch
2024-08-18 01:50:29 +08:00
- [x] Chat with the selected block
2024-08-23 02:01:14 -04:00
- [x] Slash commands
2024-08-18 01:50:29 +08:00
- [ ] Edit the selected block
2024-08-19 12:11:44 +08:00
- [ ] Smart Tab (Cursor Flow)
2024-08-15 04:11:10 +08:00
- [ ] Chat with project
- [ ] Chat with selected files
2024-08-12 23:53:28 +08:00
## Contributing
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.
2024-08-19 19:19:45 -04:00
See [wiki ](https://github.com/yetone/avante.nvim/wiki ) for more recipes and tricks.
2024-08-19 08:35:36 -04:00
2024-08-18 22:20:29 -04:00
2024-08-12 23:53:28 +08:00
## License
2024-08-15 10:33:22 +08:00
avante.nvim is licensed under the Apache License. For more details, please refer to the [LICENSE ](./LICENSE ) file.