From fed5dbb88124a6f256ba842a36c26cf9c24d9c2a Mon Sep 17 00:00:00 2001 From: jensonjohnathon Date: Mon, 15 Sep 2025 14:53:34 +0200 Subject: [PATCH] =?UTF-8?q?Lua=20Snippets=20f=C3=BCr=20Latex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaSnip/all.lua | 8 ++++++++ init.lua | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 LuaSnip/all.lua diff --git a/LuaSnip/all.lua b/LuaSnip/all.lua new file mode 100644 index 00000000..ca2efbdd --- /dev/null +++ b/LuaSnip/all.lua @@ -0,0 +1,8 @@ +return { + -- A snippet that expands the trigger "hi" into the string "Hello, world!". + require('luasnip').snippet({ trig = 'hi' }, { t 'Hello, world!' }), + + -- To return multiple snippets, use one `return` statement per snippet file + -- and return a table of Lua snippets. + require('luasnip').snippet({ trig = 'foo' }, { t 'Another snippet.' }), +} diff --git a/init.lua b/init.lua index b98ffc61..be4296ee 100644 --- a/init.lua +++ b/init.lua @@ -244,6 +244,18 @@ rtp:prepend(lazypath) -- To update plugins you can run -- :Lazy update -- +-- Yes, we're just executing a bunch of Vimscript, but this is the officially +-- endorsed method; see https://github.com/L3MON4D3/LuaSnip#keymaps +vim.cmd [[ +" Use Tab to expand and jump through snippets +imap luasnip#expand_or_jumpable() ? 'luasnip-expand-or-jump' : '' +smap luasnip#jumpable(1) ? 'luasnip-jump-next' : '' + +" Use Shift-Tab to jump backwards through snippets +imap luasnip#jumpable(-1) ? 'luasnip-jump-prev' : '' +smap luasnip#jumpable(-1) ? 'luasnip-jump-prev' : '' +]] + -- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). @@ -266,6 +278,32 @@ require('lazy').setup({ -- }) -- end, -- } + -- LuaSnip (Snippet Engine) + { + 'L3MON4D3/LuaSnip', + version = 'v2.*', -- stabile Version + build = 'make install_jsregexp', -- optional, für advanced regex + config = function() + local luasnip = require 'luasnip' + -- Lade VSCode-kompatible Snippets, falls du welche hast + require('luasnip.loaders.from_vscode').lazy_load() + require('luasnip.loaders.from_lua').load { paths = '~/.config/nvim/LuaSnip/' } + + -- einfache Keymaps + vim.keymap.set({ 'i' }, '', function() + luasnip.expand() + end, { silent = true }) + vim.keymap.set({ 'i', 's' }, '', function() + luasnip.jump(1) + end, { silent = true }) + vim.keymap.set({ 'i', 's' }, '', function() + luasnip.jump(-1) + end, { silent = true }) + end, + }, + + -- Optionale Snippet-Sammlung + { 'rafamadriz/friendly-snippets' }, -- -- Here is a more advanced example where we pass configuration -- options to `gitsigns.nvim`.