Core Keybindings: Fluency Through Repetition

Avante’s keybindings are designed for minimal disruption. To internalize them:

  1. <Leader>aa (Chat Interface):

    • Use this to start a persistent dialogue for complex tasks (e.g., debugging across multiple steps).
    • Example: Ask “Why does this API call fail?” → Follow up with “How can I retry it with exponential backoff?”
  2. <Leader>as (Submit & Continue):

    • After selecting code in visual mode, submit it with <Leader>as and keep editing while Avante processes it in the background.
  3. <Leader>ac (Clear):

    • Clears the chat history. Use this when switching contexts (e.g., moving from debugging to documentation).
  4. <Leader>ae: (Edit/Explain) the AI’s response. Opens the last response in a buffer for direct editing or deeper analysis.

  5. Command-Line Integration (:Avante):

    • Ideal for quick, single-action tasks. For example:
      :Avante Add error handling to this function.  
    • Works in normal mode (contextual to the cursor) or visual mode (selected code).

Pro Tip: Map <Leader>as to <C-Enter> for a more intuitive “submit” action:

vim.keymap.set("n", "<C-Enter>", "<Leader>as", { remap = true })  

Multi-File Prompts: Advanced Context Handling

Avante reads referenced files’ contents to provide accurate, context-aware responses.

Syntax Deep Dive

  1. Absolute vs. Relative Paths:

    • Use absolute paths (/project/src/utils.js) for files outside your current working directory.
    • Relative paths (src/components/Button.js) work if your Neovim session is in the project root.
  2. Wildcards for Bulk Analysis:

    :Avante Review all [src/hooks/*.js] for redundant API calls.  
  3. Combining Active and External Files:

    :Avante Update the validation logic in [%] to match [lib/schemas/userSchema.ts].  

Gotcha: Avante includes the entire content of referenced files. Avoid overly large files unless necessary.


Custom Prompts: Tailored Automation

Create commands for repetitive tasks, reducing prompt-writing overhead.

Example: Auto-Generate Component Docs

vim.api.nvim_create_user_command("ComponentDoc", function()  
  require("avante").ask([[  
    Generate documentation for the Vue component in [%].  
    Include props, events, and usage examples.  
    Format as Markdown.  
  ]])  
end, {})  

Run :ComponentDoc to generate docs for the current file.

Example: Cross-File Refactor Command

vim.api.nvim_create_user_command("RefactorStyles", function()  
  local current_file = vim.fn.expand("%")  
  require("avante").ask("Migrate CSS styles from [" .. current_file .. "] to Tailwind classes. Refer to [styles/guide.md] for conventions.")  
end, {})  

Code Actions: Streamlined Refactoring

  1. Inline Refactor:

    • Select code → Run :'<,'>Avante Convert this to a reusable function.
    • Avante replaces the selection directly with the improved code.
  2. Explain & Annotate:

    • Select a complex regex → :'<,'>Avante Explain this regex step-by-step.
  3. Interactive Debugging:

    • Pass error logs by pasting them into the chat (<Leader>aa) and asking:
      Here’s the error from [src/api/client.js]:  
      [paste error log]  
      How do I fix it?  
      

Combining Avante with Telescope: Supercharged File Selection

Telescope’s fuzzy-finding makes referencing files in prompts effortless. Below is a step-by-step integration:

1. Create a Custom Telescope Picker

Add this Lua function to your config to select files and feed them to Avante:

local function avante_prompt_with_files()  
  local pickers = require("telescope.pickers")  
  local finders = require("telescope.finders")  
  local conf = require("telescope.config").values  
  
  -- Open Telescope to select files  
  pickers.new({  
    prompt_title = "Select Files for Avante Prompt",  
    finder = finders.new_oneshot_job({ "git", "ls-files" }), -- or any file list  
    sorter = conf.generic_sorter({}),  
    attach_mappings = function(prompt_bufnr, map)  
      -- On selection, pass files to Avante  
      map("i", "<CR>", function()  
        local actions = require("telescope.actions")  
        local action_state = require("telescope.actions.state")  
        local selected = action_state.get_selected_entry()  
        actions.close(prompt_bufnr)  
  
        -- Prompt user for query  
        local query = vim.fn.input("Avante Query: ")  
        local files = string.format("[%s]", selected.value)  
        vim.cmd(":Avante " .. query .. " " .. files)  
      end)  
      return true  
    end,  
  }):find()  
end  

2. Map to a Key

Add a shortcut to trigger the picker:

vim.keymap.set("n", "<Leader>af", avante_prompt_with_files, { desc = "Avante: Prompt with Telescope Files" })  

3. Usage Examples

  1. Compare Selected Files:
    • Press <Leader>af → Select src/utils/logger.js → Enter query:
      Compare this with [src/utils/old/logger.js]. What improvements were made?  
      
  2. Batch Documentation:
    • Select multiple files in Telescope (see multi-select plugin) → Ask:
      Generate a summary of changes across these files for the changelog.  
      

4. Enhance with Predefined Queries

Modify the picker to include common prompts (e.g., “Refactor”, “Review”):

local query_options = {  
  "Review for readability",  
  "Compare with previous version",  
  "Generate documentation",  
}  
  
-- Add this to the Telescope picker’s attach_mappings:  
local query = vim.fn.input("Avante Query: ", "", "customlist,v:lua.require'my_module'.query_complete")  

Real-World Workflow: From Question to Solution

Scenario: You’re debugging a React component that’s not updating correctly.

  1. Gather Context:
    • Open the component file (Component.js) and its test (Component.test.js).
  2. Multi-File Prompt:
    :Avante The test [Component.test.js] passes, but [%] doesn’t update when props change. Why?  
  3. Implement Fix:
    • Avante suggests a missing useEffect dependency.
  4. Refactor with Code Action:
    • Select the code block → :'<,'>Avante Add missing dependencies and memoize this function.

Troubleshooting Workflow Integration

  1. Overloaded Context:
    • If Avante’s response is slow or irrelevant, narrow the scope:
      :Avante Focus only on the `validateUser` function in [src/models/user.js].  
  2. Ambiguous Prompts:
    • Add structure:
      :Avante Improve this code. Follow these steps:  
      1. Check for redundant API calls.  
      2. Simplify state management.  
      3. Add error logging.  

Final Tip: Make It a Habit

  • Daily Practice: Start each coding session with one Avante prompt (e.g., “Review this function”).
  • Template Prompts: Save common queries in a scratch file for quick copy-pasting.
  • Collaborate: Share your custom commands with your team to standardize code reviews.

By integrating Avante into routines like file selection (Telescope), refactoring (code actions), and debugging (multi-file prompts), it becomes a seamless extension of your problem-solving process—not just a tool, but a collaborator.