Mercurial > dotfiles
diff .chezmoitemplates/init.lua @ 724:e442bbd36b87
feat: copy current file path relative to repo root and line nr to clipboard
author | zegervdv <zegervdv@me.com> |
---|---|
date | Fri, 09 Dec 2022 17:59:37 +0100 |
parents | 20256729c355 |
children | 624d8036f5ae |
line wrap: on
line diff
--- 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', '<leader>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'