Last active
November 14, 2024 06:45
-
-
Save AceCodePt/13da35fba518df842a84650497f16714 to your computer and use it in GitHub Desktop.
Fixed Terminal Yanking Nvim
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
vim.api.nvim_create_autocmd({ "TextYankPost" }, { | |
pattern = "term://*", | |
callback = function() | |
local width = vim.api.nvim_win_get_width(0) - 2 | |
local offset = vim.api.nvim_win_get_cursor(0)[2] | |
local yanked_text = vim.fn.getreg("+") | |
local new_str = "" | |
local count = 1 | |
while true do | |
local next_index = string.find(yanked_text, "\n", count) | |
if next_index == nil then | |
new_str = new_str .. string.sub(yanked_text, count, string.len(yanked_text)) | |
break | |
end | |
if next_index - count + offset >= width then | |
new_str = new_str .. string.sub(yanked_text, count, next_index - 1) | |
else | |
new_str = new_str .. string.sub(yanked_text, count, next_index) | |
end | |
count = next_index + 1 | |
offset = 0 | |
end | |
vim.fn.setreg("+", new_str) | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment