-
Is there an existing Action to copy the filename and path of a result to the clipboard, rather than opening it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
You could define the action yourself as ...
actions = {
["ctrl-y"] = {
fn = function(selected)
vim.fn.setreg("*", selected[1])
end,
desc = ...,
}, where |
Beta Was this translation helpful? Give feedback.
-
My setup for fzf-lua now contains this but the key combo does nothing. Could anyone point out how to correct? local path = require("fzf-lua.path")
get_line_and_path = function(selected, opts)
local file_and_path = path.entry_to_file(selected[1], opts)
if vim.o.clipboard == "unnamed" then
vim.fn.setreg([[*]], file_and_path)
elseif vim.o.clipboard == "unnamedplus" then
vim.fn.setreg([[+]], file_and_path)
else
vim.fn.setreg([["]], file_and_path)
end
-- copy to the yank register regardless
vim.fn.setreg([[0]], file_and_path)
end
require("fzf-lua").setup({
"border-fused",
fzf_opts = { ["--wrap"] = true },
previewers = {
builtin = {
syntax_limit_b = -102400, -- 100KB limit on highlighting files
},
},
winopts = {
preview = {
wrap = true,
},
},
grep = {
rg_glob = true,
-- first returned string is the new search query
-- second returned string are (optional) additional rg flags
-- @return string, string?
rg_glob_fn = function(query, opts)
local regex, flags = query:match("^(.-)%s%-%-(.*)$")
-- If no separator is detected will return the original query
return (regex or query), flags
end,
},
defaults = {
git_icons = false,
file_icons = false,
color_icons = false,
formatter = "path.filename_first",
},
actions = {
files = {
["ctrl-y"] = get_line_and_path,
},
},
})
|
Beta Was this translation helpful? Give feedback.
-
Thanks for 'teaching me to fish' a little there! I was able to print the table with |
Beta Was this translation helpful? Give feedback.
Now is the time to get your hands dirty troubleshooting :)
If it prints “function 0x” you gave it a function object to print, try
print(1, object)
so you can track the code route and you’ll figure it out, see which route is taken and which register is saved, if you want only the clipboard you only need this linevim.fn.setreg([[+]], file_and_path)
but it needs to be changed tovim.fn.setreg([[+]], file_and_path.path)
(as entry is a table).To dump table objects use
vim.print(file_and_path)
.