fix line number readout for my fancy 'copy file ref' functionality
This commit is contained in:
@@ -111,9 +111,18 @@ vim.keymap.set("n", "<leader>yr", ":let @+=expand('%:.')<CR>", { desc = "Relativ
|
||||
vim.keymap.set("n", "<leader>cf", ":let @+=expand('%:t')<CR>", { desc = "Current filename to clipboard" })
|
||||
vim.keymap.set({'n','v'}, '<leader>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 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)
|
||||
|
||||
Reference in New Issue
Block a user