Created
September 9, 2025 05:24
-
-
Save tomaszkubacki/336e529f80b71fbc96eb2b0101f34795 to your computer and use it in GitHub Desktop.
Execute current line in neovim terminal (LazyVim)
This file contains hidden or 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 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