nvim: got friendly snippets working

This commit is contained in:
Daniel Lundin 2022-01-09 22:29:09 +01:00
parent e7f78f287a
commit 6943f77d30

View file

@ -5,7 +5,7 @@ return require('packer').startup(function()
use 'wbthomason/packer.nvim'
use 'ray-x/lsp_signature.nvim'
use 'jose-elias-alvarez/nvim-lsp-ts-utils'
use 'L3MON4D3/LuaSnip'
use 'rafamadriz/friendly-snippets'
use {
'b3nj5m1n/kommentary',
@ -20,6 +20,13 @@ return require('packer').startup(function()
end
}
use {
'L3MON4D3/LuaSnip',
config = function()
require("luasnip/loaders/from_vscode").lazy_load()
end
}
use {
'hrsh7th/nvim-cmp',
requires = {
@ -28,11 +35,17 @@ return require('packer').startup(function()
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
},
config = function()
local cmp = require'cmp'
-- local cmp = require('hrsh7th/nvim-cmp')
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({
@ -50,25 +63,34 @@ return require('packer').startup(function()
}),
},
documentation = {
border = 'rounded'
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-u>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
select = false,
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }),
['<C-y>'] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
@ -93,7 +115,10 @@ return require('packer').startup(function()
priority = 1,
},
{ name = 'luasnip' },
{
name = 'luasnip',
priority = 4,
},
{
name = 'tmux',
priority = 2,