Added some custom snippets and ability to expand with more
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
|
||||
"LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" },
|
||||
"aerial.nvim": { "branch": "master", "commit": "2aeafd99937602fc40609ffffbdd2f99d77343e9" },
|
||||
"cellular-automaton.nvim": { "branch": "main", "commit": "11aea08aa084f9d523b0142c2cd9441b8ede09ed" },
|
||||
"cellular-automaton.nvim": { "branch": "main", "commit": "1606e9d5d04ff254023c3f3c62842d065708d6d3" },
|
||||
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
|
||||
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
|
||||
"cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" },
|
||||
@@ -17,14 +17,14 @@
|
||||
"hererocks": { "branch": "master", "commit": "c9c5444dea1e07e005484014a8231aa667be30b6" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "7527af40ddd4a93a02911be570b32609b9d4ea53" },
|
||||
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "e942edf5c85b6a2ab74059ea566cac5b3e1514a4" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "f75e877f5266e87523eb5a18fcde2081820d087b" },
|
||||
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
|
||||
"nvim": { "branch": "main", "commit": "4965db2d6155c25db4e8417465fc2703fdf4c2b7" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "ead2fbc4893fdd062e1dd0842679a48bfb7bac5c" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "f98fa715acc975c2dd5fb5ba7ceddeb1cc725ad2" },
|
||||
"nvim-surround": { "branch": "main", "commit": "ae298105122c87bbe0a36b1ad20b06d417c0433e" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "110bdf91e3fcbc019efbac13026ae4ad9e4ededf" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "1c9136332840edee0c593f2f4f89598c8ed97f5f" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "2497d9558d12023e058de2782fc25bc4f405f870" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "402377242b04be3f4f0f3720bd952df86e946c30" },
|
||||
"oil.nvim": { "branch": "master", "commit": "add50252b5e9147c0a09d36480d418c7e2737472" },
|
||||
"plenary": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
|
||||
|
||||
@@ -8,6 +8,7 @@ return {
|
||||
opts = {
|
||||
-- Define your formatters
|
||||
formatters_by_ft = {
|
||||
go = { "gofmt" },
|
||||
lua = { "stylua" },
|
||||
python = { "isort", "black" },
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
|
||||
@@ -8,22 +8,7 @@ return {
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"hrsh7th/nvim-cmp",
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
dependencies = {
|
||||
"rafamadriz/friendly-snippets",
|
||||
"benfowler/telescope-luasnip.nvim",
|
||||
},
|
||||
config = function(_, opts)
|
||||
if opts then
|
||||
require("luasnip").config.setup(opts)
|
||||
end
|
||||
vim.tbl_map(function(type)
|
||||
require("luasnip.loaders.from_" .. type).lazy_load()
|
||||
vim.keymap.set("n", "<leader>ts", "<cmd>Telescope luasnip<CR>", { desc = "Search Snippets" })
|
||||
end, { "vscode", "snipmate", "lua" })
|
||||
end,
|
||||
},
|
||||
"L3MON4D3/LuaSnip",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"j-hui/fidget.nvim",
|
||||
},
|
||||
@@ -103,14 +88,6 @@ return {
|
||||
s = cmp.mapping.confirm({ select = true }),
|
||||
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
|
||||
}),
|
||||
["<Tab>"] = function(fallback)
|
||||
local ls = require("luasnip")
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "luasnip" }, -- For luasnip users.
|
||||
|
||||
40
lua/haelnorr/lazy/luasnip.lua
Normal file
40
lua/haelnorr/lazy/luasnip.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
return {
|
||||
"L3MON4D3/LuaSnip",
|
||||
dependencies = {
|
||||
"rafamadriz/friendly-snippets",
|
||||
"benfowler/telescope-luasnip.nvim",
|
||||
},
|
||||
opts = {
|
||||
history = true,
|
||||
updateevents = "TextChanged,TextChangedI",
|
||||
},
|
||||
config = function(_, opts)
|
||||
local ls = require("luasnip")
|
||||
if opts then
|
||||
ls.config.setup(opts)
|
||||
end
|
||||
vim.tbl_map(function(type)
|
||||
require("luasnip.loaders.from_" .. type).lazy_load()
|
||||
vim.keymap.set("n", "<leader>ts", "<cmd>Telescope luasnip<CR>", { desc = "Search Snippets" })
|
||||
end, { "vscode", "snipmate", "lua" })
|
||||
local lua_snippets = require("haelnorr.snippets.lua")
|
||||
ls.add_snippets("lua", lua_snippets)
|
||||
local go_snippets = require("haelnorr.snippets.go")
|
||||
ls.add_snippets("go", go_snippets)
|
||||
vim.keymap.set({ "i", "s" }, "<C-k>", function()
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
end
|
||||
end)
|
||||
vim.keymap.set({ "i", "s" }, "<C-j>", function()
|
||||
if ls.jumpable(-1) then
|
||||
ls.jump(-1)
|
||||
end
|
||||
end)
|
||||
vim.keymap.set("i", "<C-l>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
}
|
||||
@@ -18,6 +18,12 @@ return {
|
||||
{ "<leader>o", group = "Open plugin", icon = { icon = "", color = "yellow" } },
|
||||
{ "<leader>r", group = "Refactoring", mode = { "n", "x" } },
|
||||
{ "<leader>v", group = "LSP Actions", icon = { icon = "" } },
|
||||
{ "<leader>l", "<cmd>LspRestart<CR>", desc = "Restart LSP" },
|
||||
|
||||
{ "<leader><leader>", group = "Reload Plugins", icon = { icon = "" } },
|
||||
{ "<leader><leader>w", "<cmd>Lazy reload which-key.nvim<CR>", desc = "Reload Which-key" },
|
||||
{ "<leader><leader>s", "<cmd>Lazy reload LuaSnip<CR>", desc = "Reload LuaSnip" },
|
||||
{ "<leader><leader>l", "<cmd>Lazy reload nvim-lspconfig<CR>", desc = "Reload LSP" },
|
||||
|
||||
-- Harpoon
|
||||
-- Quick jumps and show list
|
||||
|
||||
31
lua/haelnorr/snippets/go.lua
Normal file
31
lua/haelnorr/snippets/go.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local c = ls.choice_node
|
||||
local f = ls.function_node
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
return {
|
||||
s(
|
||||
"efi",
|
||||
fmt(
|
||||
[[
|
||||
{}, err := {}({})
|
||||
if err != nil {{
|
||||
return "", false, {}
|
||||
}}
|
||||
]],
|
||||
{
|
||||
i(1, "var"),
|
||||
i(2, "f"),
|
||||
i(3, ""),
|
||||
c(4, {
|
||||
f(function(args)
|
||||
return 'errors.Wrap(err, "' .. args[1][1] .. '")'
|
||||
end, { 2 }),
|
||||
t("err"),
|
||||
}),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
14
lua/haelnorr/snippets/lua.lua
Normal file
14
lua/haelnorr/snippets/lua.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local i = ls.insert_node
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
return {
|
||||
s(
|
||||
"snip",
|
||||
fmt('s("{}", fmt(\n "{}"\n, {{\n {}\n}})),', {
|
||||
i(1, "trigger"),
|
||||
i(2, "snippet body"),
|
||||
i(3, "insert nodes"),
|
||||
})
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user