diff options
| author | Robert Günzler <r@gnzler.io> | 2023-01-25 11:05:54 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2023-03-21 12:35:43 +0100 |
| commit | 2fa8017df618d43a24994ab55eab140d3889bc57 (patch) | |
| tree | d16f34f4ce7b5930cf29d9a562ecc6170faf1891 /.vim/lua/plugins.lua | |
| parent | 20eeff217f410a274e1893eb3ea717e7402b4620 (diff) | |
vim: fix cmp config
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/lua/plugins.lua')
| -rw-r--r-- | .vim/lua/plugins.lua | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index d250a4a..cc81aed 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -307,7 +307,7 @@ local pluginspec = { { 'hrsh7th/nvim-cmp', - event = 'InsertEnter', + event = { 'InsertEnter', 'CmdlineEnter' }, dependencies = { -- 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', @@ -349,53 +349,59 @@ local pluginspec = { border = 'solid', }, }, - mapping = cmp.mapping.preset.insert({ - ['<c-space>'] = cmp.mapping.complete(), + mapping = { + ['<c-space>'] = cmp.complete, ['<cr>'] = cmp.mapping(function(fallback) - if luasnip.expandable() then - luasnip.expand() - elseif cmp.visible() then - cmp.mapping.confirm({ select = true }) + if cmp.visible() then + cmp.confirm({ select = true }) else fallback() end - end), + end, { 'i', 's' }), ['<c-n>'] = cmp.mapping(function(fallback) - if luasnip.locally_jumpable(1) then - luasnip.jump(1) - elseif cmp.visible() then - cmp.select_next_item() + if cmp.visible() then + cmp.select_next_item({ behavior = require('cmp.types').cmp.SelectBehavior.Select }) else fallback() end - end), + end, { 'i', 's' }), ['<c-p>'] = cmp.mapping(function(fallback) - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - elseif cmp.visible() then - cmp.select_prev_item() + if cmp.visible() then + cmp.select_prev_item({ behavior = require('cmp.types').cmp.SelectBehavior.Select }) else fallback() end - end), + end, { 'i', 's' }), ['<tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + else + fallback() + end + end, { 'i', 'c', 's' }), + ['<s-tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + -- NOTE: poor mans replacement for cmp.confirm without expanding snippet + cmp.select_next_item({ behavior = require('cmp.types').cmp.SelectBehavior.Insert }) + cmp.close() + else + fallback() + end + end, { 'i', 's' }), + ['<c-tab>'] = cmp.mapping(function(fallback) if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() - elseif cmp.visible() then - cmp.mapping.confirm({ select = true }) else fallback() end - end), - ['<s-tab>'] = cmp.mapping(function(fallback) + end, { 'i', 's' }), + ['<c-s-tab>'] = cmp.mapping(function(fallback) if luasnip.locally_jumpable(-1) then luasnip.jump(-1) - elseif cmp.visible() then - cmp.select_prev_item() else fallback() end - end), + end, { 'i', 's' }), -- map c-j/k for luasnip choice nodes ['<c-j>'] = cmp.mapping(function(fallback) if luasnip.choice_active() then @@ -411,9 +417,13 @@ local pluginspec = { fallback() end end, { 'i', 's' }), - ['<s-pagedown>'] = cmp.mapping.scroll_docs(-4), - ['<s-pageup>'] = cmp.mapping.scroll_docs(4), - }), + ['<s-pagedown>'] = cmp.mapping(function() + cmp.scroll_docs(-4) + end, { 'i', 's' }), + ['<s-pageup>'] = cmp.mapping(function() + cmp.scroll_docs(4) + end, { 'i', 's' }), + }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) @@ -447,6 +457,7 @@ local pluginspec = { item.menu = menus[entry.source.name] return item end, + expandable_indicator = true, }, }) cmp.setup.cmdline({ '/', '?', '@' }, { @@ -460,13 +471,27 @@ local pluginspec = { }, }) cmp.setup.cmdline(':', { - mapping = vim.tbl_extend('force', cmp.mapping.preset.cmdline(), { + mapping = { ['<c-r>'] = cmp.mapping({ c = function() vim.cmd.Telescope('command_history') end, }), - }), + ['<c-n>'] = cmp.mapping({ + c = function() + if cmp.visible() then + cmp.select_next_item({ behavior = require('cmp.types').cmp.SelectBehavior.Insert }) + end + end, + }), + ['<c-p>'] = cmp.mapping({ + c = function() + if cmp.visible() then + cmp.select_prev_item({ behavior = require('cmp.types').cmp.SelectBehavior.Insert }) + end + end, + }), + }, sources = cmp.config.sources({ { name = 'path' }, }, { |