A readme explaining how to make neovim work fast
| 1 | return { |
| 2 | -- copilot |
| 3 | { |
| 4 | "zbirenbaum/copilot.lua", |
| 5 | cmd = "Copilot", |
| 6 | build = ":Copilot auth", |
| 7 | event = "BufReadPost", |
| 8 | opts = { |
| 9 | suggestion = { |
| 10 | enabled = not vim.g.ai_cmp, |
| 11 | auto_trigger = false, |
| 12 | hide_during_completion = vim.g.ai_cmp, |
| 13 | keymap = { |
| 14 | accept = false, -- handled by nvim-cmp / blink.cmp |
| 15 | next = "<M-]>", |
| 16 | prev = "<M-[>", |
| 17 | }, |
| 18 | }, |
| 19 | panel = { enabled = false }, |
| 20 | filetypes = { |
| 21 | markdown = true, |
| 22 | help = true, |
| 23 | }, |
| 24 | }, |
| 25 | }, |
| 26 | |
| 27 | -- chat config |
| 28 | { |
| 29 | "CopilotC-Nvim/CopilotChat.nvim", |
| 30 | branch = "main", |
| 31 | cmd = "CopilotChat", |
| 32 | opts = function() |
| 33 | local user = vim.env.USER or "User" |
| 34 | user = user:sub(1, 1):upper() .. user:sub(2) |
| 35 | return { |
| 36 | prompts = { |
| 37 | Docs = { |
| 38 | prompt = "Add docstrings that clearly explain parameters and returns with the correct format.", |
| 39 | system = "You write good docs.", |
| 40 | description = "Add structured, language-aware documentation", |
| 41 | }, |
| 42 | }, |
| 43 | auto_insert_mode = true, |
| 44 | question_header = " " .. user .. " ", |
| 45 | answer_header = " Copilot ", |
| 46 | model = "gpt-4o", |
| 47 | window = { |
| 48 | width = 0.4, |
| 49 | }, |
| 50 | } |
| 51 | end, |
| 52 | keys = { |
| 53 | { "<c-s>", "<CR>", ft = "copilot-chat", desc = "Submit Prompt", remap = true }, |
| 54 | { "<leader>a", "", desc = "+ai", mode = { "n", "v" } }, |
| 55 | { |
| 56 | "<leader>af", |
| 57 | function() |
| 58 | local cpc = require("CopilotChat") |
| 59 | vim.cmd("normal vaf") |
| 60 | cpc.open({ include_contexts_in_prompt = true }) |
| 61 | end, |
| 62 | desc = "Query function", |
| 63 | }, |
| 64 | { |
| 65 | "<leader>ad", |
| 66 | function() |
| 67 | local cpc = require("CopilotChat") |
| 68 | vim.cmd("normal vaf") |
| 69 | cpc.ask( |
| 70 | "Add docstrings that clearly explain parameters and returns with the correct indentations using tabs and newlines." |
| 71 | ) |
| 72 | end, |
| 73 | desc = "Add docs to function", |
| 74 | mode = "n", |
| 75 | }, |
| 76 | { |
| 77 | "<leader>aa", |
| 78 | function() |
| 79 | return require("CopilotChat").toggle() |
| 80 | end, |
| 81 | desc = "Toggle (CopilotChat)", |
| 82 | mode = { "n", "v" }, |
| 83 | }, |
| 84 | { |
| 85 | "<leader>ax", |
| 86 | function() |
| 87 | return require("CopilotChat").reset() |
| 88 | end, |
| 89 | desc = "Clear (CopilotChat)", |
| 90 | mode = { "n", "v" }, |
| 91 | }, |
| 92 | { |
| 93 | "<leader>aq", |
| 94 | function() |
| 95 | vim.ui.input({ |
| 96 | prompt = "Quick Chat: ", |
| 97 | }, function(input) |
| 98 | if input ~= "" then |
| 99 | require("CopilotChat").ask(input) |
| 100 | end |
| 101 | end) |
| 102 | end, |
| 103 | desc = "Quick Chat (CopilotChat)", |
| 104 | mode = { "n", "v" }, |
| 105 | }, |
| 106 | { |
| 107 | "<leader>ap", |
| 108 | function() |
| 109 | require("CopilotChat").select_prompt() |
| 110 | end, |
| 111 | desc = "Prompt Actions (CopilotChat)", |
| 112 | mode = { "n", "v" }, |
| 113 | }, |
| 114 | { |
| 115 | "<C-a>", |
| 116 | "<Esc><C-y>q", |
| 117 | ft = "copilot-chat", |
| 118 | desc = "Submit and close", |
| 119 | mode = { "n", "i" }, |
| 120 | remap = true, |
| 121 | }, |
| 122 | }, |
| 123 | config = function(_, opts) |
| 124 | vim.env.OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") |
| 125 | local chat = require("CopilotChat") |
| 126 | |
| 127 | vim.api.nvim_create_autocmd("BufEnter", { |
| 128 | pattern = "copilot-chat", |
| 129 | callback = function() |
| 130 | vim.opt_local.relativenumber = false |
| 131 | vim.opt_local.number = false |
| 132 | end, |
| 133 | }) |
| 134 | |
| 135 | chat.setup(opts) |
| 136 | end, |
| 137 | }, |
| 138 | } |