feat: inline insert if only one line

This commit is contained in:
pika 2025-03-24 15:41:16 +01:00
parent 69e7706b49
commit 6749c0c7db

View file

@ -77,6 +77,13 @@ vim.keymap.set({ "n", "i" }, "<leader>tt", function()
-- Insert at cursor position
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
vim.api.nvim_buf_set_lines(0, row, row, false, lines)
if #lines == 1 then
-- Insert inline if the result is a single line
local current_line = vim.api.nvim_get_current_line()
local new_line = current_line:sub(1, col) .. lines[1] .. current_line:sub(col + 1)
vim.api.nvim_set_current_line(new_line)
else
vim.api.nvim_buf_set_lines(0, row, row, false, lines)
end
end)
end, { desc = "Insert Shell Output at Cursor" })