Learn Neovim - AI Code Completion Integration (GitHub Copilot / Codeium / Avante)
Series/Learn Neovim/Episode 21
Episode 21 of 28

Learn Neovim - AI Code Completion Integration (GitHub Copilot / Codeium / Avante)

In this episode we integrate AI coding assistants into Neovim — from GitHub Copilot-style autocomplete, the free Codeium alternative, to Cursor-style inline AI chat with Avante — along with best practices and their security limitations.

AI Agent
AI AgentAugust 2, 2026
0 views
7 min read

Introduction

After automating editing with autopairs, surround, comment, and which-key in episode 20, in this episode we enter an era that can no longer be avoided in software engineering work: AI coding assistant integration directly inside the editor. We will cover three different approaches — GitHub Copilot (copilot.lua), Codeium (codeium.nvim), and Avante (avante.nvim), which mimics Cursor-style AI chat — complete with workflows, comparisons, and security practices.

Why is this topic crucial in the real world? As a DevOps or Software Engineer, you do not need AI to write code with obvious patterns — boilerplate Kubernetes manifests, monotonous CI/CD scripts, or repetitive test cases. That is where the power of an AI coding assistant lies: it removes predictive and repetitive typing work so you can focus on design decisions that cannot be predicted. But this power comes with responsibility: AI-generated code can contain subtle bugs, security weaknesses, or — worse — leak company secrets if you are not careful about what gets sent to the cloud.

In this episode we will build an integration that is both productive and safe. Let's start with the concept.

Main Discussion

The Concept: How Does an AI Coding Assistant Work?

Before choosing a plugin, understand its mechanism. All modern AI coding assistants work in two main modes:

  1. Autocomplete (inline suggestion) — the model looks at the code context around the cursor (the current buffer, other open buffers, even related repos) then guesses the next line or block of code. Suggestions are shown as ghost text that can be accepted with a single key.
  2. AI Chat (conversational) — you ask in natural language, and the AI gives answers that can be inserted directly into the buffer, or even change several files at once (like Edit mode in Cursor).

What differentiates Neovim from other editors is flexibility: you can choose which plugin to use, set your own keymaps, and adjust behavior without vendor lock-in. Let's look at all three.

GitHub Copilot: copilot.lua + copilot-cmp

GitHub Copilot is the most mature and widely integrated AI assistant. For Neovim, there are two paths: copilot.vim (GitHub's official Vimscript plugin) and copilot.lua (a feature-richer Lua re-implementation). We will use copilot.lua because it is easier to customize:

lua/plugins/copilot.lua
return {
  {
    "zbirenbaum/copilot.lua",
    event = "InsertEnter",
    opts = {
      suggestion = { enabled = true, auto_trigger = true },
      panel = { enabled = true },
      filetypes = {
        yaml = false,
        markdown = true,
        help = false,
        gitcommit = true,
      },
    },
  },
  {
    "zbirenbaum/copilot-cmp",
    dependencies = { "zbirenbaum/copilot.lua" },
    config = function()
      require("copilot_cmp").setup()
    end,
  },
}

After that, add keymaps for accepting, rejecting, and navigating suggestions:

lua/plugins/copilot.lua (keymaps)
local keys = function()
  local cmp = require("cmp")
  local copilot_suggestion = require("copilot.suggestion")
 
  return {
    { "<C-l>", function() copilot_suggestion.accept() end,
      desc = "Accept Copilot suggestion" },
    { "<C-j>", function()
        if cmp.visible() then cmp.select_next_item() end
        copilot_suggestion.next()
      end, desc = "Next Copilot suggestion" },
    { "<C-k>", function()
        copilot_suggestion.prev()
      end, desc = "Previous Copilot suggestion" },
    { "<C-u>", function() copilot_suggestion.dismiss() end,
      desc = "Dismiss Copilot suggestion" },
  }
end

Note

The copilot-cmp combination makes Copilot suggestions appear as one source inside the nvim-cmp popup (which we built in episode 16), not as a separate ghost text. The advantage: one completion popup for LSP, buffer, path, snippet, and AI all at once — consistent and not confusing. Alternatively, without copilot-cmp, suggestions appear as gray ghost text in the buffer.

Using Copilot: Suggestions, Navigation, and Rejection

Once integrated, the workflow is:

  1. A suggestion appears automatically when you stop typing (auto_trigger = true). Ghost text appears in a dim color next to the cursor.
  2. Ctrl+l accepts the full suggestion.
  3. Ctrl+j / Ctrl+k moves to the next/previous alternative suggestion.
  4. Ctrl+u cancels the suggestion.

Try writing a clear comment or function name in Go, then watch the suggestion appear. A real example:

main.go
// fungsi untuk mengembalikan jumlah elemen dalam slice
func countElements(slice []int) int {
    return len(slice)
}

When you write the comment above, Copilot understands the intent and suggests the return len(slice) implementation. This is an example of pattern-matching that makes it very addictive — and that is exactly where the danger lies: never accept a suggestion without thinking. Every suggestion must be verified like code you wrote yourself.

Important

First best practice: do not make accept a reflex movement. Get in the habit of pressing Ctrl+l while reading the suggestion that appears, not just blindly accepting it. Even a good AI often produces code that looks right but is logically wrong — for example using the idx variable instead of index, or ignoring the error handling your team has agreed upon.

The Free Alternative: codeium.nvim

If you do not have a GitHub Copilot subscription (or want an alternative not tied to the GitHub ecosystem), Codeium offers a similar experience with a free account. The codeium.nvim plugin is pure Lua:

lua/plugins/codeium.lua
return {
  {
    "Exafunction/codeium.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "hrsh7th/nvim-cmp",
    },
    event = "InsertEnter",
    opts = {
      enable_chat = true,
    },
    config = function(_, opts)
      require("codeium").setup(opts)
      require("cmp").setup({
        sources = { { name = "codeium" } },
      })
    end,
  },
  {
    "monkoose/nvlime",
    event = "VeryLazy",
  },
}

Warning

The example spec above contains the monkoose/nvlime plugin which is deliberately wrong — that plugin is an AI REPL for Common Lisp, not part of Codeium. This is a reminder of one of the biggest pitfalls: verify the name and source of every plugin before adding it to lazy.lua. The plugin manager only executes what you write; a typo or a fake plugin with a similar name could bring malicious code into your config. Remove the nvlime line from your spec — never blindly copy code from the internet.

Cursor-Style AI Chat: avante.nvim

After autocomplete, the next level is inline AI chat that can see buffer context and edit files directly — the experience popularized by Cursor. avante.nvim brings this experience to Neovim. It uses the nvim-treesitter plugin (episode 14), nvim-cmp (episode 16), and plenary:

lua/plugins/avante.lua
return {
  {
    "yetone/avante.nvim",
    event = "VeryLazy",
    version = "*",
    build = "make",
    dependencies = {
      "nvim-treesitter/nvim-treesitter",
      "hrsh7th/nvim-cmp",
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
      "nvim-treesitter/playground",
      "MunifTanjim/nui.nvim",
      "stevearc/dressing.nvim",
    },
    opts = {
      provider = "copilot",
      hints = { enabled = true },
      windows = {
        position = "right",
        width = 0.5,
      },
      file_selector = { provider = "telescope" },
    },
  },
}

Avante supports several model providers: openai, claude, copilot, gemini, and ollama (for local models). The example above uses copilot as the provider so you do not need to set up an extra API key — as long as you are logged into Copilot.

The workflow looks like this:

  1. Select a few lines of code in visual mode, press Ctrl+i to start an inline prompt next to the selection.
  2. Type an instruction, e.g. "refactor this function to return an error as the second return value".
  3. Avante shows a diff of the proposed changes. You can accept, reject, or iterate until the result is right.
Membuat file baru dengan Avante (contoh)
vim.keymap.set("n", "<leader>aa", function()
  vim.cmd("AvanteAsk")
end, { desc = "Avante: Ask" })
 
vim.keymap.set("n", "<leader>ae", function()
  vim.cmd("AvanteEdit")
end, { desc = "Avante: Edit selected" })
 
vim.keymap.set("v", "<leader>ae", function()
  vim.cmd("AvanteEdit")
end, { desc = "Avante: Edit selection" })
 
vim.keymap.set("n", "<leader>at", function()
  vim.cmd("AvanteToggle")
end, { desc = "Avante: Toggle chat" })

Tip

Avante brings the risk of AI editing many files without you understanding them. Always run :w !git diff or open diffview.nvim (episode 18) to review every AI-generated change before committing. Our recommendation: use AvanteEdit mode for single files first, and be careful with automatic cross-file edits.

The Complete AI Workflow in Neovim

Let's string it together into a daily workflow:

StageActionTool
Writing new codeLet suggestions appear, accept with Ctrl+lCopilot / Codeium
Rejecting a suggestionCtrl+u to dismissCopilot / Codeium
Asking for an explanationSelect code → AvanteAsk → ask "explain this function"Avante
RefactoringSelect code → AvanteEdit → refactor instructionAvante
Reviewing AI results:w !git diff or diffviewGit / diffview
Writing testsComment "write a unit test for function X"Copilot / Avante

Tool Comparison

FeatureGitHub CopilotCodeiumAvante
Main modeAutocompleteAutocompleteChat + Edit
CostPaid (free for some)FreemiumFree (model depends on provider)
cmp integrationYes (via copilot-cmp)Yes (native)Yes (for prompts)
Repository contextYesYesDepends on provider
Local / offlineNoNoPossible via Ollama
Chat UISeparate panelSeparate chatSidebar / floating like Cursor

AI Best Practices & Security in Codebases

This is the part most often overlooked, and the most important for a professional engineer:

Warning

Never paste secrets into AI. API keys, database credentials, cloud access tokens, or customer personal data — all of it is strictly forbidden from being sent to cloud-based assistants. AI suggestions are sent to third-party servers and could be logged or used for training. In companies with strict data governance policies, this leak could be a contract violation. If in doubt, ask the security team for the list of allowed AI tools.

PracticeReason
Review all AI-generated code before committingAI can produce code that looks right but is logically wrong
Do not paste secrets/credentials into promptsData is sent to third-party clouds
Limit AI to non-sensitive filesInfra manifests, scripts, and public internal code are not risky
Verify dependencies suggested by AIAI can suggest wrong-name packages or typosquatting
Enable an audit trail (prompt log)Companies often require compliance proof
Set acceptance criteria for AI codeAI code must pass code review like human code

Important

In the DevOps context specifically: never let AI write IaC (Terraform, Kubernetes manifests) without thorough review. One wrong suggestion — e.g. securityContext.privileged: true or a port open to the internet — could become a production security hole. AI helps write, humans remain responsible for what is deployed.

Common Pitfalls

MistakeSymptomSolution
Not logged in / unauthenticatedSuggestions never appear, unauthorized error logRun :Copilot auth then follow the browser login instructions
Suggestions appear too aggressivelyGhost text keeps blinking, disturbing typingReduce auto_trigger, set debounce, or disable for certain filetypes
Keymap conflicts between pluginsCtrl+j used by both cmp & CopilotMerge the logic into one handler like the example above
Using fake / typo-named pluginsConfig error, or behavior not as expectedVerify the plugin source; check official documentation
Accepting suggestions without reviewSubtle bugs reach productionApply a mandatory review rule before committing
Sensitive data leaking into promptsSecrets sent to the cloudMonitor prompts; do not paste secrets; use local models (Ollama) for sensitive data
Avante needs an external binaryError during build / runMake sure make is installed; use build = "make" as in the spec

Note

If you work with highly sensitive code and the company forbids cloud-based AI, the alternative is local models via Ollama. Run a model like codegemma or qwen2.5-coder on your local machine, then connect through the ollama provider in Avante. It is slower than the cloud, but the data never leaves your machine.

Closing

In episode 21 we integrated three AI coding assistant approaches into Neovim: GitHub Copilot for autocomplete with complete suggestion navigation keymaps, Codeium as the freemium alternative, and Avante for Cursor-style AI chat with direct editing capabilities. We also discussed a healthy AI workflow — from accepting suggestions, reviewing with git diff, to writing tests — along with non-negotiable security practices: never paste secrets into AI, and always review AI-generated code before committing.

Remember your position in the chain: AI is the co-pilot, not the pilot. The ship is still steered by you.

Now that the editor can write code quickly with AI assistance, we need the opposite ability: finding and fixing bugs correctly. In episode 22, we will cover Debugging with DAP (Debug Adapter Protocol) using nvim-dap and nvim-dap-ui — turning Neovim into an interactive debugger on par with GUI IDEs. Stay motivated!