guonaihong / config.lua

私有lunarvim配置文件,为方便clone,设置为public
Apache License 2.0
0 stars 0 forks source link

4. copilot 生效 #4

Open guonaihong opened 1 year ago

guonaihong commented 1 year ago

默认安装copilot由于tab键冲突,会导致使用lunarvim不生效。这里需要修改下配置, 先禁用copilot插件里面的tab键映射。再起一个回调处理tab键

vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true
vim.g.copilot_tab_fallback = ""
local cmp = require "cmp"
-- lvim.builtin.cmp.mapping["<C-e>"] = function(fallback)
--   cmp.mapping.abort()
--   local copilot_keys = vim.fn["copilot#Accept"]()
--   if copilot_keys ~= "" then
--     vim.api.nvim_feedkeys(copilot_keys, "i", true)
--   else
--     fallback()
--   end
-- end

lvim.builtin.cmp.mapping["<Tab>"] = function(fallback)
  if cmp.visible() then
    cmp.select_next_item()
  else
    local copilot_keys = vim.fn["copilot#Accept"]()
    if copilot_keys ~= "" then
      vim.api.nvim_feedkeys(copilot_keys, "i", true)
    else
      fallback()
    end
  end
end
guonaihong commented 1 year ago

以下是这个配置的具体作用: