Here is my code from my lazy nvim config for fzf plugins:
return {
{ "junegunn/fzf" },
{
"junegunn/fzf.vim",
config = function()
vim.g.fzf_layout = { window = { width = 0.9, height = 0.6 } }
vim.g.fzf_buffers_jump = 1
vim.g.fzf_preview_window = { "right:50%", "ctrl-/" }
vim.g.fzf_action = {
["ctrl-t"] = "tab split",
["ctrl-x"] = "split",
["ctrl-v"] = "vsplit",
}
end,
keys = {
{
"<leader>sP",
function()
--vim.fn["fzf#vim#grep"]("rg 'blah' /root/.local/share/nvim/lazy", 1, {'options': '--ansi'})
vim.api.nvim_command(
'call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case \\"\\" /root/.local/share/nvim/lazy", { "options": ["--preview", "/root/.local/share/nvim/lazy/fzf.vim/bin/preview.sh {}", "--delimiter", "\\/", "--with-nth", "7.." ] } )'
--'call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case \\"\\" /root/.local/share/nvim/lazy", 1, {"options": "--ansi --preview \\"bat --color=always --style=numbers {}\\" --preview-window=:50%:wrap"}, 0)'
--'call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case \\"\\" /root/.local/share/nvim/lazy", 1)'
)
end,
desc = "Search Plugin Files",
},
},
},
}
If you are not using lazy nvim, you won't want to copy this exactly. But the important bit is in the keys
section where the call is to fzf#vim#grep
.
You can see the options are passed. Per docs, these get passed to fzf#wrap
. The --delmiter
is set to "\/". The first slash escapes the second slash which escapes the third slash. This is needed because it is a regex. But ou will probably only need to do on escape: "/".
Next arg is "--with-nth" which is set to "7..". Change the number according to how many segments of the path you need to eliminate.