Skip to content

Instantly share code, notes, and snippets.

@AlanJui
Last active February 20, 2024 07:34
Show Gist options
  • Save AlanJui/f4e0a699e7dec4374030f1848f750a3d to your computer and use it in GitHub Desktop.
Save AlanJui/f4e0a699e7dec4374030f1848f750a3d to your computer and use it in GitHub Desktop.
將 copilot.lua 置入 NvChad ,與之整合。 (Integrate copilot.lua into NvChad.)

在 NvChad 引用 copilot.lua 插件

變更程序

  1. 新增 copilot.lua 設定檔,檔案命名為:copilot.lua,置於目錄路徑:~/.config/nvim/lua/custom/configs/ 下;

  2. 變更客製化的插件設定檔: ~/.config/nvim/lua/custom/plugins.lua 。

-- file path: ~/.config/nvim/lua/custom/configs/copilot.lua
local M = {}
M.opts = {
panel = {
enabled = true,
auto_refresh = true,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>",
},
layout = {
position = "bottom", -- | top | left | right
ratio = 0.4,
},
},
suggestion = {
enabled = true,
auto_trigger = true,
debounce = 75,
keymap = {
accept = "<C-]>",
accept_word = "<C-Right>",
accept_line = "<C-End>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-[>",
},
},
filetypes = {
yaml = false,
markdown = false,
help = false,
gitcommit = false,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
}
return M
-- file path: ~/.config/nvim/lua/custom/plugins.lua
local plugings = {
-- ... all your other plugins ...
{
"zbirenbaum/copilot.lua",
lazy = false,
event = "InsertEnter",
cmd = "Copilot",
build = ":Copilot auth",
config = function()
local opts = require("custom.configs.copilot").opts
require("copilot").setup(opts)
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
{
"zbirenbaum/copilot-cmp",
config = function()
require("copilot_cmp").setup()
end,
},
},
opts = {
mapping = {
-- go to next placeholder in the snippet
["<C-n>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
-- go to previous placeholder in the snippet
["<C-p>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-y>"] = cmp.mapping.complete(),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
-- Select next item
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
-- Select prev item
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = "nvim_lsp", group_index = 2 },
{ name = "copilot", group_index = 2 },
{ name = "luasnip", group_index = 2 },
{ name = "buffer", group_index = 2 },
{ name = "nvim_lua", group_index = 2 },
{ name = "path", group_index = 2 },
},
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment