From dd31843246ccdf9783f1b54d79b5e1ee22596399 Mon Sep 17 00:00:00 2001 From: listout Date: Thu, 25 Aug 2022 01:14:33 +0530 Subject: [wip] better lua config for nvim Signed-off-by: listout --- lua/plugins/cmp.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lua/plugins/cmp.lua (limited to 'lua/plugins/cmp.lua') diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..e42b9f2 --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,72 @@ +-- luasnip setup +local luasnip = require 'luasnip' + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + view = { + entries = "custom", + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'path' }, + { name = 'buffer' }, + { name = 'nvim_lsp_signature_help' }, + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'nvim_lua' }, + }, +} +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = 'buffer' }, + }) +}) +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +require'cmp'.setup.cmdline('/', { + sources = { + { name = 'buffer' } -- cmp-buffer needed + } +}) +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +require'cmp'.setup.cmdline(':', { + sources = { + { name = 'cmdline' }, + { name = 'path' }, -- cmp-path needed + } +}) -- cgit v1.2.3