Created
August 12, 2024 19:04
-
-
Save fira42073/c5bc8d4d1f60dc73722acbbf8ab55cb4 to your computer and use it in GitHub Desktop.
LuaSnip FzfLua integration
This file contains 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 luasnip = require("luasnip") | |
local fzf_lua = require("fzf-lua") | |
local function search_snippets() | |
-- Get available snippets | |
local snippets = luasnip.available() | |
-- Flatten the snippets table and prepare entries for fzf-lua | |
local entries = {} | |
for category, snippet_list in pairs(snippets) do | |
if type(snippet_list) == "table" then | |
for _, snippet in ipairs(snippet_list) do | |
local description = snippet.description[1] or "" -- Extract the first description if available | |
local entry = string.format("%s - %s (%s) : %s", snippet.trigger, snippet.name, category, description) | |
table.insert(entries, entry) | |
end | |
end | |
end | |
-- Use fzf-lua to search through snippets | |
fzf_lua.fzf_exec(entries, { | |
prompt = "Select Snippet> ", | |
actions = { | |
["default"] = function(selected) | |
if #selected > 0 then | |
-- Extract the trigger from the selected entry | |
local trigger = selected[1]:match("^(.-)%s+-") | |
-- Insert the trigger into the current buffer and go into insert mode | |
vim.api.nvim_put({ trigger }, "c", true, true) | |
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>i", true, true, true), "n", true) | |
end | |
end, | |
}, | |
}) | |
end | |
vim.keymap.set("n", "<leader>fs", search_snippets, { desc = "FZF search snippets" }) |
Thank you @fira42073 i will try to make it work, i really look forward for seeing description and preview, i really depend on those for my snippets.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Felipe-9 good luck! I've found fzf-lua to be very robust and it replaced telescope for me.