Mercurial > dotfiles
changeset 486:3449f059b93e
Add/fix expansion mapping for snippets
author | zegervdv <zegervdv@me.com> |
---|---|
date | Tue, 09 Nov 2021 16:40:35 +0100 |
parents | 4ad3b5ada36b |
children | 0252f9494d64 |
files | .chezmoitemplates/config.vim .chezmoitemplates/init.lua |
diffstat | 2 files changed, 35 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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 <Tab> and <S-Tab> to navigate through popup menu -inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" -inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" - -" 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="<c-b>" -let g:UltiSnipsJumpBackwardTrigger="<c-z>" -let g:completion_enable_auto_paren=0 - -imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' -smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' -imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' -smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' - -" -" -" function! SendOSCClipboard(lines, regtype) call SendViaOSC52(join(a:lines, "\n"))
--- 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 @@ ['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, }, + ['<Tab>'] = 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', + }), + + ['<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 = 'nvim_lsp' },