copysource.nvim allows you to copy source code with line numbers.
function myCopy()
require('copysource').copyWithLineNum({
separator = '|',
markdown_format = true,
show_filename = true,
})
end
vim.keymap.set("v", " yn", "<CMD>lua myCopy()<CR>", { noremap = true })