Skip to content

Instantly share code, notes, and snippets.

@tomaszkubacki
Created September 9, 2025 05:24
Show Gist options
  • Select an option

  • Save tomaszkubacki/336e529f80b71fbc96eb2b0101f34795 to your computer and use it in GitHub Desktop.

Select an option

Save tomaszkubacki/336e529f80b71fbc96eb2b0101f34795 to your computer and use it in GitHub Desktop.
Execute current line in neovim terminal (LazyVim)
local function yank_line_and_send_to_terminal()
-- Yank the current line into the default register
vim.cmd('normal! ""yy')
local text = vim.fn.getreg('"')
local snacks_terminal = require("snacks.terminal")
local terminal = snacks_terminal.get()
if not terminal then
terminal = snacks_terminal.open()
end
local term_buf = terminal and terminal.buf
local term_win = terminal and terminal.win
-- Only call :show() if the window is NOT already open
local win_valid = term_win and vim.api.nvim_win_is_valid(term_win)
if not win_valid then
terminal:show()
-- refresh window handle
term_win = terminal.win
end
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
vim.schedule(function()
if term_win and vim.api.nvim_win_is_valid(term_win) then
vim.api.nvim_set_current_win(term_win)
end
vim.api.nvim_set_current_buf(term_buf)
vim.cmd("startinsert")
-- vim.api.nvim_feedkeys(text, "t", false)
-- vim.api.nvim_feedkeys("\r", "t", false) -- Enter
typewriter(text)
end)
else
vim.notify("Could not find or open terminal.", vim.log.levels.ERROR)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment