comparison .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
comparison
equal deleted inserted replaced
723:bbcf4f5b005c 724:e442bbd36b87
1091 -- Toggle options in snippets 1091 -- Toggle options in snippets
1092 vim.keymap.set('i', '<c-l>', function() 1092 vim.keymap.set('i', '<c-l>', function()
1093 if ls.choice_active() then ls.change_choice() end 1093 if ls.choice_active() then ls.change_choice() end
1094 end) 1094 end)
1095 1095
1096 -- Copy the current file and line number
1097 -- inspired by https://github.com/diegoulloao/nvim-file-location
1098 vim.keymap.set('n', '<leader>cp', function()
1099 local Path = require 'plenary.path'
1100 local current_file = Path:new(vim.fn.expand '%')
1101 local root =
1102 vim.fs.dirname(vim.fs.find({ '.hg', '.git' }, { path = tostring(current_file:parent()), upward = true })[1])
1103 local current_line = vim.fn.line '.'
1104 require('osc52').copy(current_file:make_relative(root) .. ':' .. current_line)
1105 vim.notify 'Copied file path and line number'
1106 end, { desc = 'Yank current path and line number' })
1107
1096 -- LSP config 1108 -- LSP config
1097 local lsp = require 'lspconfig' 1109 local lsp = require 'lspconfig'
1098 local null_ls = require 'null-ls' 1110 local null_ls = require 'null-ls'
1099 1111
1100 local lsp_formatting = function(bufnr) 1112 local lsp_formatting = function(bufnr)