Skip to content

Instantly share code, notes, and snippets.

@s1n7ax
Last active May 26, 2023 16:35
Show Gist options
  • Save s1n7ax/9b369ed83c910d50c9312b5c1d5a1279 to your computer and use it in GitHub Desktop.
Save s1n7ax/9b369ed83c910d50c9312b5c1d5a1279 to your computer and use it in GitHub Desktop.
LuaSnip keymaps written in lua
local ls = require('luasnip')
local M = {}
function M.expand_or_jump()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end
function M.jump_next()
if ls.jumpable(1) then
ls.jump(1)
end
end
function M.jump_prev()
if ls.jumpable(-1) then
ls.jump(-1)
end
end
function M.change_choice()
if ls.choice_active() then
ls.change_choice(1)
end
end
function M.reload_package(package_name)
for module_name, _ in pairs(package.loaded) do
if string.find(module_name, '^' .. package_name) then
package.loaded[module_name] = nil
require(module_name)
end
end
end
function M.refresh_snippets()
ls.cleanup()
M.reload_package('<update the module name here>')
end
local set = vim.keymap.set
local mode = { 'i', 's' }
local normal = { 'n' }
set(mode, '<c-i>', M.expand_or_jump)
set(mode, '<c-n>', M.jump_prev)
set(mode, '<c-l>', M.change_choice)
set(normal, ',r', M.refresh_snippets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment