fix line number readout for my fancy 'copy file ref' functionality
This commit is contained in:
@@ -111,12 +111,21 @@ 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", "<leader>cf", ":let @+=expand('%:t')<CR>", { desc = "Current filename to clipboard" })
|
||||||
vim.keymap.set({'n','v'}, '<leader>ya', function()
|
vim.keymap.set({'n','v'}, '<leader>ya', function()
|
||||||
local fname = vim.fn.expand('%:.')
|
local fname = vim.fn.expand('%:.')
|
||||||
local lines = (vim.fn.mode() == 'v' or vim.fn.mode() == 'V')
|
local mode = vim.fn.mode()
|
||||||
and (tostring(math.min(vim.fn.line("'<"), vim.fn.line("'>")))..'..'..tostring(math.max(vim.fn.line("'<"), vim.fn.line("'>"))))
|
local lines
|
||||||
or tostring(vim.fn.line('.'))
|
if mode:match("[vV\22]") then
|
||||||
local result = fname..':'..lines
|
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)
|
vim.fn.setreg('+', result)
|
||||||
print('Copied: '..result)
|
print('Copied: ' .. result)
|
||||||
end, {desc = 'Copy file path and line(s) to clipboard'})
|
end, {desc = 'Copy file path and line(s) to clipboard'})
|
||||||
|
|
||||||
-- clear search highlighting
|
-- clear search highlighting
|
||||||
|
|||||||
Reference in New Issue
Block a user