Add basic luasnip config
This commit is contained in:
parent
e1dec1ee53
commit
ad9c779b20
6 changed files with 77 additions and 3 deletions
4
init.lua
4
init.lua
|
@ -1,7 +1,7 @@
|
||||||
-- Making leader (<Leader>) key to space
|
-- Making leader (<Leader>) key to space
|
||||||
vim.g.mapleader = ","
|
vim.g.mapleader = "\\"
|
||||||
-- Making local leader (<LocalLeader>) key to backslash
|
-- Making local leader (<LocalLeader>) key to backslash
|
||||||
vim.g.maplocalleader = "\\"
|
vim.g.maplocalleader = ""
|
||||||
|
|
||||||
-- Bootstrap lazy.nvim
|
-- Bootstrap lazy.nvim
|
||||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
-- menu: Show menu when completions available (more than 1)
|
-- menu: Show menu when completions available (more than 1)
|
||||||
-- menuone: Show menu even when there is only 1 option
|
-- menuone: Show menu even when there is only 1 option
|
||||||
-- noselect: Force user to select convinient option
|
-- noselect: Force user to select convinient option
|
||||||
|
|
||||||
|
-- Load luasnip setup
|
||||||
|
require "custom.luasnip"
|
||||||
|
|
||||||
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
||||||
|
|
||||||
local lspkind = require "lspkind"
|
local lspkind = require "lspkind"
|
||||||
|
@ -25,6 +29,7 @@ local cmp = require "cmp"
|
||||||
|
|
||||||
cmp.setup {
|
cmp.setup {
|
||||||
sources = {
|
sources = {
|
||||||
|
{ name = "luasnip" },
|
||||||
{ name = "nvim_lsp" },
|
{ name = "nvim_lsp" },
|
||||||
{ name = "path" },
|
{ name = "path" },
|
||||||
{ name = "buffer" },
|
{ name = "buffer" },
|
||||||
|
@ -40,4 +45,21 @@ cmp.setup {
|
||||||
{ "i", "c" }
|
{ "i", "c" }
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Enable luasnip to handle snippet expansion for nvim-cmp
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
vim.snippet.expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
formatting = {
|
||||||
|
fields = { "abbr", "kind", "menu" },
|
||||||
|
expandable_indicator = true,
|
||||||
|
format = function(entry, vim_item)
|
||||||
|
-- Lspkind setup for icons
|
||||||
|
vim_item = kind_formatter(entry, vim_item)
|
||||||
|
return vim_item
|
||||||
|
end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
33
lua/custom/luasnip.lua
Normal file
33
lua/custom/luasnip.lua
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
local ls = require "luasnip"
|
||||||
|
local types = require "luasnip.util.types"
|
||||||
|
|
||||||
|
ls.config.set_config {
|
||||||
|
history = true,
|
||||||
|
updateevents = "TextChanged, TextChangedI",
|
||||||
|
enable_autosnippets = true
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
||||||
|
if ls.expand_or_jumpable() then
|
||||||
|
ls.expand_or_jump()
|
||||||
|
end
|
||||||
|
end, { silent = true })
|
||||||
|
|
||||||
|
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
||||||
|
if ls.jumpable() then
|
||||||
|
ls.jump(-1)
|
||||||
|
end
|
||||||
|
end, { silent = true })
|
||||||
|
|
||||||
|
vim.keymap.set({ "i", "s" }, "<c-l>", function()
|
||||||
|
if ls.choice_active() then
|
||||||
|
ls.change_choice(1)
|
||||||
|
end
|
||||||
|
end, { silent = true })
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/nvim_dev/lua/custom/luasnip.lua<CR>")
|
||||||
|
|
||||||
|
-- Load custom snippets
|
||||||
|
for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/custom/snippets/*.lua", true)) do
|
||||||
|
loadfile(ft_path)()
|
||||||
|
end
|
9
lua/custom/plugins/luasnip.lua
Normal file
9
lua/custom/plugins/luasnip.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
-- follow latest release.
|
||||||
|
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||||
|
-- install jsregexp (optional!).
|
||||||
|
build = "make install_jsregexp"
|
||||||
|
}
|
||||||
|
}
|
10
lua/custom/snippets/lua.lua
Normal file
10
lua/custom/snippets/lua.lua
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
local ls = require "luasnip"
|
||||||
|
|
||||||
|
|
||||||
|
print("hello from lua snips")
|
||||||
|
|
||||||
|
ls.add_snippets("lua", {
|
||||||
|
ls.parser.parse_snippet("expand", "-- this is what was expanded kek"),
|
||||||
|
ls.parser.parse_snippet("pipa", "Pipasik"),
|
||||||
|
})
|
||||||
|
|
|
@ -7,5 +7,5 @@ set("n", "<c-l>", "<c-w><c-l>")
|
||||||
set("n", "<c-h>", "<c-w><c-h>")
|
set("n", "<c-h>", "<c-w><c-h>")
|
||||||
|
|
||||||
-- Bindings for reloading LUA files (used when working with lua files)
|
-- Bindings for reloading LUA files (used when working with lua files)
|
||||||
set("n", "<leader>x", "<cmd>.lua<CR>", { desc = "Execute the current lne" })
|
-- set("n", "<leader>x", "<cmd>.lua<CR>", { desc = "Execute the current lne" })
|
||||||
set("n", "<leader><leader>x", "<cmd>source %<CR>", { desc = "Execute the current file" })
|
set("n", "<leader><leader>x", "<cmd>source %<CR>", { desc = "Execute the current file" })
|
||||||
|
|
Loading…
Reference in a new issue