Add tab bindings for luasnip
This commit is contained in:
parent
cca7a8d750
commit
ac03f482fb
2 changed files with 80 additions and 59 deletions
|
@ -1,64 +1,83 @@
|
||||||
return {
|
return {
|
||||||
"hrsh7th/nvim-cmp",
|
"hrsh7th/nvim-cmp",
|
||||||
event = "InsertEnter", -- Only load plugin when in INSERT mode
|
event = "InsertEnter", -- Only load plugin when in INSERT mode
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"hrsh7th/cmp-buffer", -- source for text in buffer
|
"hrsh7th/cmp-buffer", -- source for text in buffer
|
||||||
"hrsh7th/cmp-path", -- source for file system paths
|
"hrsh7th/cmp-path", -- source for file system paths
|
||||||
{
|
{
|
||||||
"L3MON4D3/LuaSnip",
|
"L3MON4D3/LuaSnip",
|
||||||
-- follow latest release.
|
-- follow latest release.
|
||||||
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||||
},
|
},
|
||||||
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
||||||
"rafamadriz/friendly-snippets", -- useful snippets
|
"rafamadriz/friendly-snippets", -- useful snippets
|
||||||
"onsails/lspkind.nvim", -- vs-code like pictograms
|
"onsails/lspkind.nvim", -- vs-code like pictograms
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Load custom snippets from path
|
-- Load custom snippets from path
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
require("luasnip.loaders.from_vscode").lazy_load({ paths = vim.fn.stdpath("config") .. "/snippets/" })
|
require("luasnip.loaders.from_vscode").lazy_load({ paths = vim.fn.stdpath("config") .. "/snippets/" })
|
||||||
|
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
local luasnip = require("luasnip")
|
local luasnip = require("luasnip")
|
||||||
local lspkind = require("lspkind")
|
local lspkind = require("lspkind")
|
||||||
|
|
||||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
completion = {
|
completion = {
|
||||||
completeopt = "menu,menuone,preview,noselect",
|
completeopt = "menu,menuone,preview,noselect",
|
||||||
},
|
},
|
||||||
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
luasnip.lsp_expand(args.body)
|
luasnip.lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
mapping = cmp.mapping.preset.insert({
|
mapping = cmp.mapping.preset.insert({
|
||||||
["<C-k>"] = cmp.mapping.select_prev_item(),
|
["<C-k>"] = cmp.mapping.select_prev_item(),
|
||||||
["<C-j>"] = cmp.mapping.select_next_item(),
|
["<C-j>"] = cmp.mapping.select_next_item(),
|
||||||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
["<C-e>"] = cmp.mapping.close(),
|
["<C-e>"] = cmp.mapping.close(),
|
||||||
["<CR>"] = cmp.mapping.confirm { select = true },
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||||
}),
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
-- sources for autocompletion
|
if cmp.visible() then
|
||||||
-- !! Priority is important - autocompletion will be ordered from top to bottom
|
cmp.select_next_item()
|
||||||
sources = cmp.config.sources({
|
elseif luasnip.locally_jumpable(1) then
|
||||||
{ name = "nvim_lsp" }, -- nvim LSP servers
|
luasnip.jump(1)
|
||||||
{ name = "luasnip" }, -- snippets
|
else
|
||||||
{ name = "buffer" }, -- text within current buffer
|
fallback()
|
||||||
{ name = "path" }, -- file system paths
|
end
|
||||||
}),
|
end, { "i", "s" }),
|
||||||
|
|
||||||
-- configure lspkind for vs-code like pictograms in completion menu
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
formatting = {
|
if cmp.visible() then
|
||||||
format = lspkind.cmp_format({
|
cmp.select_prev_item()
|
||||||
maxwidth = 50,
|
elseif luasnip.locally_jumpable(-1) then
|
||||||
ellipsis_char = "...",
|
luasnip.jump(-1)
|
||||||
}),
|
else
|
||||||
},
|
fallback()
|
||||||
})
|
end
|
||||||
end,
|
end, { "i", "s" }),
|
||||||
|
}),
|
||||||
|
-- sources for autocompletion
|
||||||
|
-- !! Priority is important - autocompletion will be ordered from top to bottom
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = "nvim_lsp" }, -- nvim LSP servers
|
||||||
|
{ name = "luasnip" }, -- snippets
|
||||||
|
{ name = "buffer" }, -- text within current buffer
|
||||||
|
{ name = "path" }, -- file system paths
|
||||||
|
}),
|
||||||
|
|
||||||
|
-- configure lspkind for vs-code like pictograms in completion menu
|
||||||
|
formatting = {
|
||||||
|
format = lspkind.cmp_format({
|
||||||
|
maxwidth = 50,
|
||||||
|
ellipsis_char = "...",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,9 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
templates = {
|
templates = {
|
||||||
folder = "Templates"
|
folder = "Templates",
|
||||||
|
date_format = "%d.%m.%Y",
|
||||||
|
time_format = "%H:%M",
|
||||||
},
|
},
|
||||||
-- disable adding properties on top of file on save
|
-- disable adding properties on top of file on save
|
||||||
disable_frontmatter = true,
|
disable_frontmatter = true,
|
||||||
|
|
Loading…
Reference in a new issue