Add snippet mappings & being porting snippets

This commit is contained in:
2024-03-05 23:36:41 +00:00
parent 781cb49cb2
commit 0c7636dfa5
4 changed files with 104 additions and 0 deletions

76
snippets/all.lua Normal file
View File

@@ -0,0 +1,76 @@
# Global LuaSnip snippets
local luasnip = require('luasnip')
local snip = luasnip.snippet
-- local sn = luasnip.snippet_node
local text = luasnip.text_node
-- local isn = luasnip.indent_snippet_node
-- local t = luasnip.text_node
local insert = luasnip.insert_node
local func = luasnip.function_node
-- local c = luasnip.choice_node
-- local d = luasnip.dynamic_node
-- local r = luasnip.restore_node
-- local events = require("luasnip.util.events")
-- local ai = require("luasnip.nodes.absolute_indexer")
-- local extras = require("luasnip.extras")
-- local l = extras.lambda
-- local rep = extras.rep
-- local p = extras.partial
-- local m = extras.match
-- local n = extras.nonempty
-- local dl = extras.dynamic_lambda
-- local fmt = require("luasnip.extras.fmt").fmt
-- local fmta = require("luasnip.extras.fmt").fmta
-- local conds = require("luasnip.extras.expand_conditions")
-- local postfix = require("luasnip.extras.postfix").postfix
-- local types = require("luasnip.util.types")
-- local parse = require("luasnip.util.parser").parse_snippet
-- local ms = luasnip.multi_snippet
-- local k = require("luasnip.nodes.key_indexer").new_key
local snippets = {}
local function comment_prefix()
-- Get value of commentstring buffer option
local split = string.find(vim.bo.commentstring, '%s', 1, true)
if not split then
return ''
end
-- Slice commentstring prefix
local prefix = string.sub(vim.bo.commentstring, 1, split - 1)
local line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(vim.api.nvim_get_current_win())
-- Check if the current line already has prefix before the cursor
if string.find(string.sub(line, 1, cursor[2] + 1), prefix, 1, true) then
return ''
end
return prefix .. ' '
end
local function comment_suffix()
-- Get value of commentstring buffer option
local split = string.find(vim.bo.commentstring, '%s', 1, true)
if not split then
return ''
end
-- Slice commentstring suffix
local suffix = string.sub(vim.bo.commentstring, split + 2, -1)
if string.len(suffix) == 0 then
return ''
end
return ' ' .. suffix
end
for _, name in ipairs({ 'fixme', 'todo', 'hack', 'warn', 'note' }) do
table.insert(snippets,
snip(name, {
func(comment_prefix),
text(string.upper(name) .. ': '),
insert(0),
func(comment_suffix),
})
)
end
return snippets

7
snippets/all.snippets Normal file
View File

@@ -0,0 +1,7 @@
# Global SnipMate snippets
snippet shrug
¯\_(ツ)_/¯
snippet tableflip
(╯°▪°)╯︵┻━┻

2
snippets/cpp.snippets Normal file
View File

@@ -0,0 +1,2 @@
snippet array
std::array<${1:T}, ${2:N}> ${3:array};${4}