From f69e8f3c3259460fe6842a951c8c4d2728a67f57 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 3 Sep 2023 20:26:08 +0300 Subject: nvim: cmp cleanup, actually use luasnip --- .config/nvim/lua/plugins/cmp.lua | 82 +++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 7f3163f..1bc209f 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -1,16 +1,16 @@ return { { "hrsh7th/nvim-cmp", - event = "InsertEnter", dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "hrsh7th/cmp-omni", + "hrsh7th/cmp-nvim-lsp-signature-help", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip", - "rafamadriz/friendly-snippets", + "honza/vim-snippets", }, config = function() local cmp = require("cmp") @@ -49,13 +49,10 @@ return { ---@diagnostic disable-next-line: missing-fields cmp.setup({ enabled = function() - -- disable autocompletion in prompt + -- disable autocompletion in telescope prompt local buftype = vim.api.nvim_buf_get_option(0, "buftype") - if buftype == "prompt" then return false end - local context = require 'cmp.config.context' - -- disable autocompletion in comments - return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") + return buftype ~= "prompt" end, ---@diagnostic disable-next-line: missing-fields completion = { @@ -73,8 +70,6 @@ return { mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false, @@ -105,16 +100,19 @@ return { -- kind icons vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) vim_item.menu = ({ - nvim_lsp = "[lsp]", - luasnip = "[snippet]", - buffer = "[buffer]", - path = "[path]", + nvim_lsp = "[ ]", + nvim_lsp_signature_help = "[󰞋 ]", + omni = "[ ]", + luasnip = "[ ]", + buffer = "[󰮳 ]", + path = "[ ]", })[entry.source.name] return vim_item end, }, sources = { { name = "nvim_lsp" }, + { name = "nvim_lsp_signature_help" }, { name = "luasnip" }, { name = "buffer" }, { name = "path" }, @@ -128,40 +126,14 @@ return { cmp_autopairs.on_confirm_done() ) - ---@diagnostic disable-next-line: missing-fields - cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'git' }, - }, { - { name = 'buffer' }, - }) - }) - - -- use buffer source for `/` . - ---@diagnostic disable-next-line: missing-fields - cmp.setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' } - } - }) - - -- use cmdline & path source for ':' . - ---@diagnostic disable-next-line: missing-fields - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) - -- use omnifunc in vimwiki to complete paths and tags ---@diagnostic disable-next-line: missing-fields cmp.setup.filetype('vimwiki', { sources = cmp.config.sources({ - { name = 'omni' }, + { name = "omni" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, option = { disable_omnifuncs = {}, }, @@ -169,4 +141,28 @@ return { }) end, }, + { + "L3MON4D3/LuaSnip", + event = "InsertEnter", + dependencies = { + "honza/vim-snippets", + }, + build = "make install_jsregexp", + keys = { + { + "", + function() require("luasnip").expand_or_jump() end, + mode = { "i", "s" }, + }, + }, + opts = { + history = false, + region_check_events = 'InsertEnter', + delete_check_events = 'InsertLeave', + }, + config = function(_, opts) + require("luasnip").setup(opts) + require("luasnip.loaders.from_snipmate").lazy_load() + end, + }, } -- cgit v1.2.3-70-g09d2