diff options
author | listout <listout@protonmail.com> | 2022-08-25 01:14:33 +0530 |
---|---|---|
committer | listout <listout@protonmail.com> | 2022-09-01 16:26:42 +0530 |
commit | dd31843246ccdf9783f1b54d79b5e1ee22596399 (patch) | |
tree | 9b0f42dbe44fd0dd79d8de963092daf04671e6d9 /lua/plugins/cmp.lua | |
parent | f07108dca88d47eeae67587011994c6179a7d035 (diff) |
[wip] better lua config for nvim
Signed-off-by: listout <listout@protonmail.com>
Diffstat (limited to 'lua/plugins/cmp.lua')
-rw-r--r-- | lua/plugins/cmp.lua | 72 |
1 files changed, 72 insertions, 0 deletions
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({ + ['<C-d>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + ['<C-Space>'] = cmp.mapping.complete(), + ['<CR>'] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + ['<Tab>'] = 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' }), + ['<S-Tab>'] = 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 + } +}) |