nvim: Add support for using snippets
This commit is contained in:
parent
ca46007f89
commit
e24fc200ec
4 changed files with 42 additions and 1 deletions
19
nvim/.config/nvim/after/plugin/vsnip.vim
Normal file
19
nvim/.config/nvim/after/plugin/vsnip.vim
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
" Expand
|
||||||
|
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
|
||||||
|
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
|
||||||
|
|
||||||
|
" Expand or jump
|
||||||
|
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
|
||||||
|
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
|
||||||
|
|
||||||
|
" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
|
||||||
|
" See https://github.com/hrsh7th/vim-vsnip/pull/50
|
||||||
|
nmap s <Plug>(vsnip-select-text)
|
||||||
|
xmap s <Plug>(vsnip-select-text)
|
||||||
|
nmap S <Plug>(vsnip-cut-text)
|
||||||
|
xmap S <Plug>(vsnip-cut-text)
|
||||||
|
|
||||||
|
" If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.
|
||||||
|
let g:vsnip_filetypes = {}
|
||||||
|
let g:vsnip_filetypes.javascriptreact = ['javascript']
|
||||||
|
let g:vsnip_filetypes.typescriptreact = ['typescript']
|
|
@ -116,9 +116,24 @@ local on_attach = function(client, bufnr)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function set_snippet_capabilities()
|
||||||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
|
||||||
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||||
|
properties = {
|
||||||
|
'documentation',
|
||||||
|
'detail',
|
||||||
|
'additionalTextEdits',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return capabilities
|
||||||
|
end
|
||||||
|
|
||||||
local servers = { 'hls', 'rust_analyzer', 'pyls', 'tsserver' }
|
local servers = { 'hls', 'rust_analyzer', 'pyls', 'tsserver' }
|
||||||
for _, lsp in ipairs(servers) do
|
for _, lsp in ipairs(servers) do
|
||||||
nvim_lsp[lsp].setup {
|
nvim_lsp[lsp].setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
|
capabilities = set_snippet_capabilities(),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ require'compe'.setup {
|
||||||
tags = true;
|
tags = true;
|
||||||
treesitter = true;
|
treesitter = true;
|
||||||
snippets_nvim = false;
|
snippets_nvim = false;
|
||||||
vsnip = false;
|
vsnip = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ end
|
||||||
_G.tab_complete = function()
|
_G.tab_complete = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
return t "<C-n>"
|
return t "<C-n>"
|
||||||
|
elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||||
|
return t "<Plug>(vsnip-expand-or-jump)"
|
||||||
elseif check_back_space() then
|
elseif check_back_space() then
|
||||||
return t "<Tab>"
|
return t "<Tab>"
|
||||||
else
|
else
|
||||||
|
|
|
@ -163,6 +163,11 @@ local init = function ()
|
||||||
'kshenoy/vim-signature',
|
'kshenoy/vim-signature',
|
||||||
'gennaro-tedesco/nvim-peekup'
|
'gennaro-tedesco/nvim-peekup'
|
||||||
}
|
}
|
||||||
|
-- Snippets
|
||||||
|
use {
|
||||||
|
'rafamadriz/friendly-snippets',
|
||||||
|
'hrsh7th/vim-vsnip'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return require('packer').startup(init)
|
return require('packer').startup(init)
|
||||||
|
|
Loading…
Reference in a new issue