You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would really appreciate an integration for fzf-lua like for telescope, but till we are there I have created a workaround and wanted to share it here.
localluasnip=require("luasnip")
localfzf_lua=require("fzf-lua")
localfunctionsearch_snippets()
-- Get available snippetslocalsnippets=luasnip.available()
-- Flatten the snippets table and prepare entries for fzf-lualocalentries= {}
forcategory, snippet_listinpairs(snippets) doiftype(snippet_list) =="table" thenfor_, snippetinipairs(snippet_list) dolocaldescription=snippet.description[1] or"" -- Extract the first description if availablelocalentry=string.format("%s - %s (%s) : %s", snippet.trigger, snippet.name, category, description)
table.insert(entries, entry)
endendend-- Use fzf-lua to search through snippetsfzf_lua.fzf_exec(entries, {
prompt="Select Snippet> ",
actions= {
["default"] =function(selected)
if#selected>0then-- Extract the trigger from the selected entrylocaltrigger=selected[1]:match("^(.-)%s+-")
-- Insert the trigger into the current buffer and go into insert modevim.api.nvim_put({ trigger }, "c", true, true)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>i", true, true, true), "n", true)
endend,
},
})
endvim.keymap.set("n", "<leader>fs", search_snippets, { desc="FZF search snippets" })
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would really appreciate an integration for fzf-lua like for telescope, but till we are there I have created a workaround and wanted to share it here.
https://gist.github.com/fira42073/c5bc8d4d1f60dc73722acbbf8ab55cb4
Beta Was this translation helpful? Give feedback.
All reactions