Use Vscode style completion

This commit is contained in:
Ryan 2023-11-11 16:53:57 +08:00
parent df79641853
commit 68f4a6595e
Signed by: juan
GPG Key ID: 807ECD28A698D245
5 changed files with 21 additions and 16 deletions

View File

@ -11,7 +11,7 @@ o.showmode = false
o.scrolloff = 10
-- controlling
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
vim.opt.completeopt = { 'menu', 'menuone', 'noinsert' }
o.ignorecase = true
o.smartcase = true
o.smartindent = true

View File

@ -36,11 +36,13 @@ local plugins = {
},
-- TS, LSP, Completion
{
"williamboman/mason.nvim"
"williamboman/mason.nvim",
lazy = true
},
{
"nvim-treesitter/nvim-treesitter",
lazy = true,
config = function()
require("plugins.treesitter")
end
@ -51,14 +53,18 @@ local plugins = {
"nvim-treesitter/nvim-treesitter",
},
},
{
"L3MON4D3/LuaSnip",
dependencies = { "rafamadriz/friendly-snippets" },
lazy = true
},
{
"hrsh7th/nvim-cmp",
dependencies = {
{
"hrsh7th/cmp-nvim-lsp",
},
"hrsh7th/cmp-nvim-lsp",
-- TODO: check the cmp sources
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-cmdline",
"FelipeLema/cmp-async-path",
"ray-x/cmp-treesitter",

View File

@ -9,6 +9,7 @@ end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({
-- ... Your other configuration ...
snippet = {
@ -23,9 +24,7 @@ cmp.setup({
mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
cmp.confirm({ select = true })
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
@ -45,6 +44,8 @@ cmp.setup({
end, { "i", "s" }),
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items
@ -53,12 +54,15 @@ cmp.setup({
sources = cmp.config.sources({
{ name = "luasnip" }, -- For luasnip users.
{ name = "nvim_lsp" },
{ name = 'nvim_lua' },
{ name = "treesitter" },
{ name = "async_path" },
{ name = "git" },
{ name = "buffer" },
})
-- ... Your other configuration ...
}),
completion = {
completeopt = 'menu,menuone,noinsert'
}
})
cmp.setup.cmdline({ '/', '?' }, {

View File

@ -20,7 +20,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set({'n', 'i'}, '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()

View File

@ -7,8 +7,3 @@ npairs.setup({
enable_check_bracket_line = true,
check_ts = true,
})
-- If you want insert `(` after select function or method item
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp = require("cmp")
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())