# HG changeset patch # User zegervdv # Date 1670605177 -3600 # Node ID e442bbd36b874699d7981c83e83553492cf452d3 # Parent bbcf4f5b005c1d94b4ec3e1d702d79bf34fc77f8 feat: copy current file path relative to repo root and line nr to clipboard diff -r bbcf4f5b005c -r e442bbd36b87 .chezmoitemplates/init.lua --- a/.chezmoitemplates/init.lua Tue Dec 06 21:20:31 2022 +0100 +++ b/.chezmoitemplates/init.lua Fri Dec 09 17:59:37 2022 +0100 @@ -1093,6 +1093,18 @@ if ls.choice_active() then ls.change_choice() end end) +-- Copy the current file and line number +-- inspired by https://github.com/diegoulloao/nvim-file-location +vim.keymap.set('n', 'cp', function() + local Path = require 'plenary.path' + local current_file = Path:new(vim.fn.expand '%') + local root = + vim.fs.dirname(vim.fs.find({ '.hg', '.git' }, { path = tostring(current_file:parent()), upward = true })[1]) + local current_line = vim.fn.line '.' + require('osc52').copy(current_file:make_relative(root) .. ':' .. current_line) + vim.notify 'Copied file path and line number' +end, { desc = 'Yank current path and line number' }) + -- LSP config local lsp = require 'lspconfig' local null_ls = require 'null-ls'