-
Notifications
You must be signed in to change notification settings - Fork 11
/
snippets.lua
54 lines (44 loc) · 1.44 KB
/
snippets.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local ls = require "luasnip"
-- TODO: Think about `locally_jumpable`, etc.
-- Might be nice to send PR to luasnip to use filters instead for these functions ;)
vim.snippet.expand = ls.lsp_expand
---@diagnostic disable-next-line: duplicate-set-field
vim.snippet.active = function(filter)
filter = filter or {}
filter.direction = filter.direction or 1
if filter.direction == 1 then
return ls.expand_or_jumpable()
else
return ls.jumpable(filter.direction)
end
end
---@diagnostic disable-next-line: duplicate-set-field
vim.snippet.jump = function(direction)
if direction == 1 then
if ls.expandable() then
return ls.expand_or_jump()
else
return ls.jumpable(1) and ls.jump(1)
end
else
return ls.jumpable(-1) and ls.jump(-1)
end
end
vim.snippet.stop = ls.unlink_current
-- ================================================
-- My Configuration
-- ================================================
ls.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI",
override_builtin = true,
}
for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/custom/snippets/*.lua", true)) do
loadfile(ft_path)()
end
vim.keymap.set({ "i", "s" }, "<c-k>", function()
return vim.snippet.active { direction = 1 } and vim.snippet.jump(1)
end, { silent = true })
vim.keymap.set({ "i", "s" }, "<c-j>", function()
return vim.snippet.active { direction = -1 } and vim.snippet.jump(-1)
end, { silent = true })