Add luasnip

This commit is contained in:
Warren Hood 2022-11-13 06:11:33 +02:00
parent 799708b9f9
commit ed32743a88
5 changed files with 35 additions and 6 deletions

View file

@ -0,0 +1,7 @@
local ls = require("luasnip")
local s = ls.snippet
return {
ls.parser.parse_snippet("test", "fn $1($2) {\n$0}"),
}

View file

@ -5,7 +5,7 @@ cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body)
end,
vim.lsp.buf.format,
},
@ -26,7 +26,7 @@ cmp.setup({
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" }, -- For vsnip users.
{ name = "luasnip" },
{ name = "treesitter" },
}, {
{ name = "buffer" },

View file

@ -29,7 +29,7 @@ map('n', '<C-B>', ':NvimTreeToggle<CR>')
map('n', '<S-t>', ':ToggleTerm<CR>')
map('t', '<S-t>', '<C-\\><C-n>:ToggleTerm<CR>')
-- Pane navigation
--[[ -- Pane navigation
map('n', '<C-h>', ':wincmd h<CR>')
map('n', '<C-j>', ':wincmd j<CR>')
map('n', '<C-k>', ':wincmd k<CR>')
@ -38,8 +38,20 @@ map('n', '<C-l>', ':wincmd l<CR>')
map('t', '<C-h>', '<C-\\><C-n>:wincmd h<CR>')
map('t', '<C-j>', '<C-\\><C-n>:wincmd j<CR>')
map('t', '<C-k>', '<C-\\><C-n>:wincmd k<CR>')
map('t', '<C-l>', '<C-\\><C-n>:wincmd l<CR>')
map('t', '<C-l>', '<C-\\><C-n>:wincmd l<CR>') ]]
-- Pane management
map('n', '<leader>sv', ':vsplit<CR>', { desc = 'Split Vertical' })
map('n', '<leader>sh', ':split<CR>', { desc = 'Split Horizontal' })
-- luasnip
vim.cmd[[
" Use Tab to expand and jump through snippets
imap <silent><expr> <C-k> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>'
smap <silent><expr> <C-k> luasnip#jumpable(1) ? '<Plug>luasnip-jump-next' : '<Tab>'
" Use Shift-Tab to jump backwards through snippets
imap <silent><expr> <C-j> luasnip#jumpable(-1) ? '<Plug>luasnip-jump-prev' : '<S-Tab>'
smap <silent><expr> <C-j> luasnip#jumpable(-1) ? '<Plug>luasnip-jump-prev' : '<S-Tab>'
]]

View file

@ -24,4 +24,14 @@ require'nvim-treesitter.configs'.setup {
}
-- luasnip config
require("luasnip").config.set_config({ -- Setting LuaSnip config
-- Enable autotriggered snippets
enable_autosnippets = true,
-- Use Tab (or some other key if you prefer) to trigger visual selection
store_selection_keys = "<Tab>",
})
require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/LuaSnip/"})

View file

@ -36,8 +36,8 @@ require("packer").startup(function()
use("hrsh7th/cmp-path")
use("hrsh7th/cmp-cmdline")
use("hrsh7th/nvim-cmp")
use("hrsh7th/cmp-vsnip")
use("hrsh7th/vim-vsnip")
use("saadparwaiz1/cmp_luasnip")
use("L3MON4D3/LuaSnip")
-- Treesitter
use("nvim-treesitter/nvim-treesitter")