Automatically apply skeleton snippets to certain filetypes if configured
This commit is contained in:
@@ -126,3 +126,13 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||
vim.opt_local.foldmethod = "marker"
|
||||
end,
|
||||
})
|
||||
-- snippets
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "snippets",
|
||||
group = configgroup,
|
||||
callback = function()
|
||||
vim.opt_local.expandtab = false
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 4
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
-- idea stolen from: https://vi.stackexchange.com/a/42370
|
||||
local skelconfig = vim.api.nvim_create_augroup('SKEL_CONFIG', { clear = true })
|
||||
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
|
||||
group = skelconfig,
|
||||
callback = function()
|
||||
-- another autocmd so it doesn't conflict
|
||||
-- with other plugins that like to insert text on file open
|
||||
vim.api.nvim_create_autocmd("VimEnter", {
|
||||
group = skelconfig,
|
||||
callback = function()
|
||||
-- stop if buffer is not empty!
|
||||
if vim.fn.line("$") ~= 1 or vim.fn.getline(1) ~= "" then
|
||||
return
|
||||
end
|
||||
local ls = require('luasnip')
|
||||
local snippets = ls.get_snippets(vim.bo.ft)
|
||||
for _, snippet in ipairs(snippets) do
|
||||
if snippet["name"] == "_skeleton" then
|
||||
ls.snip_expand(snippet)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
return {
|
||||
"L3MON4D3/LuaSnip",
|
||||
version = "v2.*", -- just because the docs mention it
|
||||
|
||||
14
.config/nvim/snippets/vimwiki.snippets
Normal file
14
.config/nvim/snippets/vimwiki.snippets
Normal file
@@ -0,0 +1,14 @@
|
||||
snippet _skeleton Create initial diary entry
|
||||
= `strftime("%-d. %b")`: ${1:summary} =
|
||||
%% `strftime("%Y-%m-%d")`
|
||||
|
||||
${0}
|
||||
|
||||
snippet xdia Create initial diary entry
|
||||
= `strftime("%-d. %b")`: ${1:summary} (xdia) =
|
||||
%% `strftime("%Y-%m-%d")`
|
||||
|
||||
${0}
|
||||
|
||||
snippet xtodo Create a new todo
|
||||
* [ ] ${0}
|
||||
@@ -1,10 +1,10 @@
|
||||
snippet xscript Create initial skeleton
|
||||
snippet _skeleton Create initial skeleton
|
||||
<script setup lang="ts">
|
||||
${1}
|
||||
${0}${1}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
${2:<div>$3</div>}
|
||||
<${2:div}>$3</$2>
|
||||
</template>
|
||||
|
||||
snippet xpagemeta Add page meta
|
||||
|
||||
Reference in New Issue
Block a user