add custom mapping for filepath/filename selections
This commit is contained in:
parent
c516919105
commit
44715b62b8
|
@ -0,0 +1,48 @@
|
|||
local utils = require 'custom.utils'
|
||||
|
||||
vim.keymap.set('n', '<leader>yn', function()
|
||||
local filename = vim.fn.expand '%:t'
|
||||
vim.fn.setreg('+', filename)
|
||||
end, { desc = '[Y]ank file [N]ame' })
|
||||
|
||||
vim.keymap.set('n', '<leader>yp', function()
|
||||
local filepath = vim.fn.expand '%:p'
|
||||
vim.fn.setreg('+', filepath)
|
||||
end, { desc = '[Y]ank file [P]ame' })
|
||||
|
||||
vim.keymap.set('n', '<leader>ys', function()
|
||||
local filepath = vim.fn.expand '%:p'
|
||||
local filename = vim.fn.expand '%:t'
|
||||
local modify = vim.fn.fnamemodify
|
||||
|
||||
local vals = {
|
||||
['BASENAME'] = modify(filename, ':r'),
|
||||
['EXTENSION'] = modify(filename, ':e'),
|
||||
['FILENAME'] = filename,
|
||||
['PATH (CWD)'] = modify(filepath, ':.'),
|
||||
['PATH (HOME)'] = modify(filepath, ':~'),
|
||||
['PATH'] = filepath,
|
||||
['URI'] = vim.uri_from_fname(filepath),
|
||||
}
|
||||
|
||||
local options = vim.tbl_filter(function(val)
|
||||
return vals[val] ~= ''
|
||||
end, vim.tbl_keys(vals))
|
||||
if vim.tbl_isempty(options) then
|
||||
utils.notify('No values to copy', vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
table.sort(options)
|
||||
vim.ui.select(options, {
|
||||
prompt = 'Choose to copy to clipboard:',
|
||||
format_item = function(item)
|
||||
return ('%s: %s'):format(item, vals[item])
|
||||
end,
|
||||
}, function(choice)
|
||||
local result = vals[choice]
|
||||
if result then
|
||||
utils.notify(('Copied: `%s`'):format(result))
|
||||
vim.fn.setreg('+', result)
|
||||
end
|
||||
end)
|
||||
end, { desc = '[Y]ank [S]elector' })
|
|
@ -5,6 +5,7 @@
|
|||
vim.opt.relativenumber = true
|
||||
vim.g.have_nerd_font = true
|
||||
|
||||
require 'custom.mappings'
|
||||
require('lazy').setup {
|
||||
require 'kickstart.plugins.indent_line',
|
||||
require 'kickstart.plugins.autopairs',
|
||||
|
|
|
@ -77,7 +77,6 @@ return {
|
|||
local filepath = node:get_id()
|
||||
local filename = node.name
|
||||
local modify = vim.fn.fnamemodify
|
||||
|
||||
local vals = {
|
||||
['BASENAME'] = modify(filename, ':r'),
|
||||
['EXTENSION'] = modify(filename, ':e'),
|
||||
|
|
Loading…
Reference in New Issue