From bc06d78d18c1384d91aaaa06bf6d08e48bf68fdb Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Tue, 6 May 2025 14:27:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20nvim:=20cmp=20=E8=AA=BF=E6=95=B4?= =?UTF-8?q?=E9=A0=86=E5=BA=8F=E8=AE=93=E4=B9=8B=E5=BE=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=99=82=E6=9B=B4=E5=90=88=E7=90=86=E7=9B=B4=E8=A6=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nvim/exact_lua/lsp/exact_config/cmp.lua | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/dot_config/nvim/exact_lua/lsp/exact_config/cmp.lua b/dot_config/nvim/exact_lua/lsp/exact_config/cmp.lua index 09e7fd5..28ab3f9 100644 --- a/dot_config/nvim/exact_lua/lsp/exact_config/cmp.lua +++ b/dot_config/nvim/exact_lua/lsp/exact_config/cmp.lua @@ -18,6 +18,36 @@ cmp.setup({ -- require("cmp.config").set_onetime({ sources = {} }) end, }, + -- 設定來源 + -- + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + -- { name = 'vsnip' }, -- For vsnip users. + { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + { name = 'path' }, + }), + + -- 按鍵對應 + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + -- [""] = cmp.mapping.scroll_docs(-4), --已知會衝到,先關閉 + -- [""] = cmp.mapping.scroll_docs(4), --已知會衝到,先關閉 + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + + -- AI範例: + -- [""] = cmp.mapping.select_next_item(), + -- [""] = cmp.mapping.select_prev_item(), + -- [""] = cmp.mapping.confirm({ select = true }), + }), + + -- 外觀設定 window = { completion = { winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", @@ -36,30 +66,6 @@ cmp.setup({ return kind end, }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - -- [""] = cmp.mapping.scroll_docs(-4), --已知會衝到,先關閉 - -- [""] = cmp.mapping.scroll_docs(4), --已知會衝到,先關閉 - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - - -- AI範例: - -- [""] = cmp.mapping.select_next_item(), - -- [""] = cmp.mapping.select_prev_item(), - -- [""] = cmp.mapping.confirm({ select = true }), - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - -- { name = 'vsnip' }, -- For vsnip users. - { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - { name = 'path' }, - }), }) -- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below