diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 8fa3351..af7d336 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -1,3 +1,11 @@ +-- Define a convenience function for feeding keys +local function feed_keys(keys, mode) + -- Convert special notation (e.g., ) to internal key codes + local termcodes = vim.api.nvim_replace_termcodes(keys, true, false, true) + -- Feed the keys into Neovim + vim.api.nvim_feedkeys(termcodes, mode, false) +end + -- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here @@ -56,3 +64,8 @@ vim.keymap.set("n", "ct", function() LazyVim.format({ force = true }) end, 500) end, { desc = "Tidy typescript code" }) +-- AI implementation from comment +vim.keymap.set("v", "ai", function() + vim.cmd("AvanteEdit") + feed_keys("Do what the first comment says. Do nothing if there is no actionable comment.", "i") +end, { desc = "AI implement what the comment says" }) diff --git a/lua/plugins/avante.lua b/lua/plugins/avante.lua new file mode 100644 index 0000000..922c117 --- /dev/null +++ b/lua/plugins/avante.lua @@ -0,0 +1,50 @@ +return { + "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 + provider = "openai", + openai = { + model = "gpt-4o-mini", + }, + }, + -- 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" }, + }, + }, +}