Update luasnip configuration
Replace usages of custom keybinding functions with `vim.keymap.set()`.
This commit is contained in:
parent
cdd3ff23b7
commit
73965bd501
|
@ -1,13 +1,7 @@
|
||||||
if not pcall(require, "luasnip") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local api = vim.api
|
|
||||||
local fn = vim.fn
|
|
||||||
|
|
||||||
local ls = require "luasnip"
|
local ls = require "luasnip"
|
||||||
|
|
||||||
local snippet = ls.snippet
|
local snippet = ls.snippet
|
||||||
|
local i = ls.insert_node
|
||||||
local t = ls.text_node
|
local t = ls.text_node
|
||||||
|
|
||||||
local shortcut = function(val)
|
local shortcut = function(val)
|
||||||
|
@ -37,8 +31,8 @@ end
|
||||||
|
|
||||||
local snippets = {}
|
local snippets = {}
|
||||||
|
|
||||||
for _, ft_path in ipairs(api.nvim_get_runtime_file("lua/opdavies/snippets/ft/*.lua", true)) do
|
for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/opdavies/snippets/ft/*.lua", true)) do
|
||||||
local ft = fn.fnamemodify(ft_path, ":t:r")
|
local ft = vim.fn.fnamemodify(ft_path, ":t:r")
|
||||||
snippets[ft] = make(loadfile(ft_path)())
|
snippets[ft] = make(loadfile(ft_path)())
|
||||||
|
|
||||||
ls.add_snippets(ft, snippets[ft])
|
ls.add_snippets(ft, snippets[ft])
|
||||||
|
@ -56,42 +50,29 @@ ls.config.set_config {
|
||||||
updateevents = "TextChanged,TextChangedI",
|
updateevents = "TextChanged,TextChangedI",
|
||||||
}
|
}
|
||||||
|
|
||||||
local imap = require("opdavies.keymap").imap
|
|
||||||
local map = require("opdavies.keymap").map
|
|
||||||
local nmap = require("opdavies.keymap").nmap
|
|
||||||
|
|
||||||
-- Expand the current item or just to the next item within the snippet.
|
-- Expand the current item or just to the next item within the snippet.
|
||||||
map {
|
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
||||||
{ "i", "s" },
|
if ls.expand_or_jumpable() then
|
||||||
"<c-k>",
|
ls.expand_or_jump()
|
||||||
function()
|
end
|
||||||
if ls.expand_or_jumpable() then
|
end, { silent = true })
|
||||||
ls.expand_or_jump()
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
{ silent = true },
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Jump backwards.
|
-- Jump backwards.
|
||||||
map {
|
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
||||||
{ "i", "s" },
|
if ls.jumpable(-1) then
|
||||||
"<c-j>",
|
ls.jump(-1)
|
||||||
function()
|
end
|
||||||
if ls.jumpable(-1) then
|
end, { silent = true })
|
||||||
ls.jump(-1)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
{ silent = true },
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Select within a list of options.
|
-- Select within a list of options.
|
||||||
imap {
|
vim.keymap.set("i", "<c-l>", function()
|
||||||
"<c-l>",
|
if ls.choice_active() then
|
||||||
function()
|
ls.change_choice(1)
|
||||||
if ls.choice_active() then
|
end
|
||||||
ls.change_choice(1)
|
end)
|
||||||
end
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
nmap { "<leader><leader>s", "<cmd>source ~/Code/github.com/opdavies/dotfiles/config/neovim/after/plugin/luasnip.lua<CR>" }
|
vim.keymap.set(
|
||||||
|
"n",
|
||||||
|
"<leader><leader>s",
|
||||||
|
"<cmd>source ~/Code/github.com/opdavies/dotfiles/config/neovim/after/plugin/luasnip.lua<CR>"
|
||||||
|
)
|
||||||
|
|
Reference in a new issue