luozhiya / fittencode.nvim

Fitten Code AI Programming Assistant for Neovim
49 stars 8 forks source link

如何自定义快捷键 #47

Closed fgheng closed 1 month ago

fgheng commented 1 month ago

我想用alt l来代替tab,这个快捷键如何自定义呢

cxwx commented 1 month ago

覆盖 binding.lua 里面 setup_keymap() 或者外部配置, { use_default_keymaps = false, } vim.keymap.set(...)

luozhiya commented 1 month ago

@fgheng

像 @cxwx 说的一样,基本就是这两个方法

完整的实现,可以参考如下代码

local function map(mode, lhs, rhs, opts)
  opts = opts or {}
  if type(opts) == 'string' then opts = { desc = opts } end
  if opts.silent == nil then opts.silent = true end
  vim.keymap.set(mode, lhs, rhs, opts)
end

local fitten = require('fittencode')

fitten.setup({
  use_default_keymaps = false,
})

map('i', '<a-l>', function()
  if fitten.has_suggestions() then
    fitten.accept_all_suggestions()
  else
    -- ignore
  end
end, 'Accept Completion')
fgheng commented 1 month ago

多谢

luozhiya commented 1 month ago

@fgheng @cxwx

现在支持更简洁的设置了,通过修改config即可

  keymaps = {
    inline = {
      ['<TAB>'] = 'accept_all_suggestions',
      ['<C-Down>'] = 'accept_line',
      ['<C-Right>'] = 'accept_word',
      ['<C-Up>'] = 'revoke_line',
      ['<C-Left>'] = 'revoke_word',
      ['<A-\\>'] = 'triggering_completion',
    },
    chat = {
      ['q'] = 'close'
    }
  },