# HG changeset patch # User zegervdv # Date 1636472435 -3600 # Node ID 3449f059b93e7be43dbbdf3bca30fd3442c6e2b2 # Parent 4ad3b5ada36bc045c9c16b1d08f2733fc90a49aa Add/fix expansion mapping for snippets diff -r 4ad3b5ada36b -r 3449f059b93e .chezmoitemplates/config.vim --- a/.chezmoitemplates/config.vim Tue Nov 09 16:23:04 2021 +0100 +++ b/.chezmoitemplates/config.vim Tue Nov 09 16:40:35 2021 +0100 @@ -706,38 +706,6 @@ " Vinegar/NetRW autocmd FileType netrw setl bufhidden=delete " -" NCM -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Auto close popup menu when finish completion -autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif - -" Use and to navigate through popup menu -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - -" Set completeopt to have a better completion experience -set completeopt=menuone,noinsert,noselect - -" Avoid showing message extra message when using completion -set shortmess+=c - -let g:completion_enable_snippet = 'UltiSnips' -let g:UltiSnipsJumpForwardTrigger="" -let g:UltiSnipsJumpBackwardTrigger="" -let g:completion_enable_auto_paren=0 - -imap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' -smap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' -imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' -smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' - -" -" -" function! SendOSCClipboard(lines, regtype) call SendViaOSC52(join(a:lines, "\n")) diff -r 4ad3b5ada36b -r 3449f059b93e .chezmoitemplates/init.lua --- a/.chezmoitemplates/init.lua Tue Nov 09 16:23:04 2021 +0100 +++ b/.chezmoitemplates/init.lua Tue Nov 09 16:40:35 2021 +0100 @@ -221,10 +221,17 @@ requires = { 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-nvim-lsp', 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-path' }, config = function() local cmp = require 'cmp' + local luasnip = require 'luasnip' + + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil + end + cmp.setup { snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) + luasnip.lsp_expand(args.body) end, }, mapping = { @@ -236,6 +243,33 @@ [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + 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 = 'nvim_lsp' },