diff --git a/term/.config/nvim/init.lua b/term/.config/nvim/init.lua index d5f96bb..3638c14 100644 --- a/term/.config/nvim/init.lua +++ b/term/.config/nvim/init.lua @@ -111,12 +111,21 @@ vim.keymap.set("n", "yr", ":let @+=expand('%:.')", { desc = "Relativ vim.keymap.set("n", "cf", ":let @+=expand('%:t')", { desc = "Current filename to clipboard" }) vim.keymap.set({'n','v'}, 'ya', function() local fname = vim.fn.expand('%:.') - local lines = (vim.fn.mode() == 'v' or vim.fn.mode() == 'V') - and (tostring(math.min(vim.fn.line("'<"), vim.fn.line("'>")))..'..'..tostring(math.max(vim.fn.line("'<"), vim.fn.line("'>")))) - or tostring(vim.fn.line('.')) - local result = fname..':'..lines + local mode = vim.fn.mode() + local lines + if mode:match("[vV\22]") then + local start_line = vim.fn.line('v') + local end_line = vim.fn.line('.') + if start_line > end_line then + start_line, end_line = end_line, start_line + end + lines = tostring(start_line) .. '..' .. tostring(end_line) + else + lines = tostring(vim.fn.line('.')) + end + local result = fname .. ':' .. lines vim.fn.setreg('+', result) - print('Copied: '..result) + print('Copied: ' .. result) end, {desc = 'Copy file path and line(s) to clipboard'}) -- clear search highlighting