Skip to main content
Linux AI Tools

Neovim + AI = The Ultimate Terminal-Based IDE with Avante Plugin

In this article, we will explore Avante plugins that enable AI assistance directly in Neovim, enhancing your terminal-based editing experience.

Mead Naji

Linux users often prefer editors like Vim or Neovim for tasks ranging from simple file editing to managing entire projects, all directly from the terminal.

These editors are ideal for those who are deeply integrated with the terminal environment and prefer to perform all their work within it.

However, with the rise of AI tools, some Vim and Neovim users have shifted towards IDEs like VS Code and Cursor, which feature built-in AI functionality.

This shift is driven by the desire to leverage AI-assisted development without leaving the comfort of a graphical interface.

Fortunately, the Vim community, comprising skilled developers and maintainers, has created numerous plugins that integrate AI into Neovim, offering the same capabilities found in AI-powered IDEs.

As a result, there’s no need to switch from your preferred terminal-based editor. By installing the right plugin, you can seamlessly incorporate AI into your workflow within Neovim.

In this article, we will explore one of these plugins that enables AI assistance directly in Neovim, enhancing your terminal-based editing experience.

What is Avante

Avante is a Portuguese name, occasionally used in Spanish as well, meaning "let’s go". In the context of this project, it represents the invitation to enhance your coding experience with AI within Neovim. The aim of Avante is to replicate the interactive experience of the Cursor IDE inside Neovim.

Avante offers two key features: it allows full interaction with AI, functioning similarly to a standard chatbot, and it can apply changes directly to your source code.

💡
Please note that, at this time, Avante is only compatible with Neovim version 0.10.1 or later. Before proceeding with the installation, ensure that you have the required version of Neovim installed.

Installing Neovim in Linux

As mentioned earlier, the plugin is compatible with Neovim version 0.10.1 or later. If you're using an older version, you should update to the latest stable release, which, as of now, is version 0.11.0.

If you're installing Neovim for the first time, follow these steps to install the stable version:

sudo apt install neovim         [On <strong>Debian</strong>]
sudo dnf install neovim         [On <strong>RHEL</strong>]
sudo emerge -a sys-apps/neovim  [On <strong>Gentoo</strong>]
sudo apk add neovim             [On <strong>Alpine</strong>]
sudo pacman -S neovim           [On <strong>Arch</strong>]
sudo zypper install neovim      [On <strong>OpenSUSE</strong>]    
sudo pkg install neovim         [On FreeBSD]

To verify the version of Neovim you have installed, run:

nvim -v
Check Neovim Version

For example, if you're using the development version, it may show version 0.12.0.

Installing Avante in Linux

To install Avante, there are several methods available. The recommended and most efficient way is by using the lazy.nvim plugin manager.

If you do not have lazy.nvim installed, you can install it with the following command:

git clone https://github.com/folke/lazy.nvim ~/.local/share/nvim/site/pack/packer/start/lazy.nvim

Once lazy.nvim is installed, you can proceed with installing the Avante plugin. You may choose to organize your plugins in a separate file, or you can add them directly to your init.lua file.

To complete the installation, paste the following code into ~/.config/nvim/init.lua:

{
  "yetone/avante.nvim",
  event = "VeryLazy",
  version = false, -- Never set this value to "*"! Never!
  opts = {
    -- add any opts here
    -- for example
    provider = "openai",
    openai = {
      endpoint = "https://api.openai.com/v1",
      model = "gpt-4o", -- your desired model (or use gpt-4o, etc.)
      timeout = 30000, -- Timeout in milliseconds, increase this for reasoning models
      temperature = 0,
      max_completion_tokens = 8192, -- Increase this to include reasoning tokens (for reasoning models)
      --reasoning_effort = "medium", -- low|medium|high, only used for reasoning models
    },
  },
  -- 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 = {
    "nvim-treesitter/nvim-treesitter",
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    --- The below dependencies are optional,
    "echasnovski/mini.pick", -- for file_selector provider mini.pick
    "nvim-telescope/telescope.nvim", -- for file_selector provider telescope
    "hrsh7th/nvim-cmp", -- autocompletion for Avante commands and mentions
    "ibhagwan/fzf-lua", -- for file_selector provider fzf
    "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" },
    },
  },
}

Now, once you open Neovim, you will get a window like this, which tells you that there is a new plugin that needs to be installed:

Install Avante Neovim Plugin

The lazy package manager will automatically install and update the plugin.

Obtain LLM API Key

Avante supports a variety of LLMs (Large Language Models) on the backend. Before you begin using Avante, you must obtain the API key for the LLM you wish to use. If you choose to use OpenAI, you can acquire your API key here.

Once you have the API key, you will need to set it as an environment variable so that Avante can access and utilize it.

To do this, execute the following command in your terminal:

export OPENAI_API_KEY=your-api-key

By default, Avante will prioritize Claude, as it is the preferred model over OpenAI. However, you are free to select the model that best fits your specific use case.

How to Use Avante

Using Avante is both simple and efficient. It operates with keybindings that you'll need to remember for quick access.

To open Avante in the sidebar and begin asking questions, press the key combination leader+aa. This will open a chat bar where you can input your query. You can ask questions related to your current project or general inquiries.

Getting Started with Avante

Once you write your prompt, press Ctrl + S to submit it. Avante will then respond using OpenAI (or any other LLM you’ve configured in the backend).

Another useful feature of Avante is its ability to assist with specific blocks of code. To use this, simply select the code you want to inquire about, then press Leader + AA to open Avante and ask any questions related to the selected code. You can copy the output from Avante just like any other text.

Avante also provides additional functionality, such as generating and directly applying code to your files.

For instance, if you have an empty file named backup.sh, you can use Avante to generate a shell script that backs up a specified directory. To apply the generated code to the file, simply press CA.

Advanced Usage and Configuration

We'll explore how to get the most out of Avante with additional settings, integrations, and tips for advanced users looking to tailor the plugin to their specific needs.

Advanced AI Integration with Multiple Providers

Avante can integrate with several LLM providers, such as OpenAI, Claude, and others. To leverage different models, modify the configuration as follows:

provider = "claude", -- Use Claude instead of OpenAI
claude = {
  endpoint = "https://api.claude.ai/v1", -- Replace with Claude's API endpoint
  model = "claude-v2", -- Use Claude's version you prefer
  max_tokens = 4096, -- Adjust the max tokens as needed
}

Enhancing Code Suggestions

Avante can be used in combination with other Neovim plugins, such as nvim-cmp (for autocompletion) and telescope.nvim (for fuzzy file finding). You can integrate Avante’s output with these plugins to enhance your coding workflow.

For example, use Avante to generate suggestions for autocompletion based on your code’s context.

dependencies = {
  "hrsh7th/nvim-cmp",  -- Autocompletion
}

Managing Large Projects with Avante

When working with large codebases, Avante can assist with debugging and refactoring. For example, you can select a block of code that’s causing errors and ask Avante for suggestions on improving performance or fixing bugs.

  • Debugging: Select the error-prone section, open Avante, and ask, "What’s wrong with this code?"
  • Refactoring: Use Avante to suggest better ways to organize your functions, improve readability, or optimize performance.

Example Project: Building a Backup Script

Let’s go through a real-world example where Avante is used to assist with creating a shell backup script.

Open a new Neovim file: backup.sh and ask Avante to generate a script for backing up a directory:

"How can I create a backup script in bash?"
  • Avante generates a backup script, which you can copy directly into backup.sh.
  • Apply any changes directly with Ctrl + A to finalize the script.

This workflow saves time and reduces the need for external tools or IDEs.

Summary

Avante is a powerful plugin for Neovim users looking to integrate AI capabilities directly into their editor without needing to switch to external AI-powered editors like Cursor.

This guide provides a brief overview of how Avante can be effectively utilized within Neovim.