Last active
September 10, 2024 06:49
-
-
Save s1n7ax/9b369ed83c910d50c9312b5c1d5a1279 to your computer and use it in GitHub Desktop.
LuaSnip keymaps written in lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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