From e2c10e5f3be1945a34debf6c8f82d3ce26cbb2b3 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 13 Nov 2024 10:09:16 -0800 Subject: [PATCH] Disable copilot for some files --- neovim/lua/plugins/copilot.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/neovim/lua/plugins/copilot.lua b/neovim/lua/plugins/copilot.lua index f056225..68f0a10 100644 --- a/neovim/lua/plugins/copilot.lua +++ b/neovim/lua/plugins/copilot.lua @@ -1,20 +1,30 @@ local utils = require("utils") local M = {} +-- Accept copilot suggestion function M.copilot_accept() local suggest = vim.fn["copilot#GetDisplayedSuggestion"]() if next(suggest.item) ~= nil then - print("accept cp") return vim.fn["copilot#Accept"]("\\") else return utils.t("") end end -M.setup = function() +function M.setup() + -- Replace keymap for copilot to accept with and , similar to fish shell vim.g.copilot_no_tab_map = false utils.keymap_set("i", "", M.copilot_accept, { expr = true, replace_keycodes = false, noremap = true }) utils.keymap_set("i", "", M.copilot_accept, { expr = true, replace_keycodes = false, noremap = true }) + + -- Create autocmd to disable copilot for certain filetypes that may contain sensitive information + vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { + pattern = { ".env*", "*secret*", "*API_KEY*", "*TOKEN*" }, + command = "let b:copilot_enabled = 0", + group = vim.api.nvim_create_augroup("CopilotDisable", { + clear = true, + }), + }) end M.setup()