Skip to content

How to invoke the expansion of LuaSnip snippets programmatically in other .lua files #970

Discussion options

You must be logged in to vote

@L3MON4D3 Your idea worked perfectly. I added the named-snippets.lua file in .config/nvim/lua (the same directory as texshortcuts.lua and then added the following code to the latter file:

-- Get text under cursor
local text_under_cursor = get_text_under_cursor()
-- Clear current line
vim.api.nvim_set_current_line("") -- clear current line

local luasnip = require("luasnip")
local fg = require("named-snippets").fg -- Retrieve named snippet
luasnip.snip_expand(fg) -- Invoke LuaSnip figure environment creation snippet
vim.api.nvim_feedkeys(text_under_cursor, "t", true) -- Fill in figure include path 

Thank you very much for your help. The work you do on LuaSnip is appreciated.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@L3MON4D3
Comment options

@kylefhartzenberg
Comment options

@L3MON4D3
Comment options

@kylefhartzenberg
Comment options

Answer selected by kylefhartzenberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants