Skip to content

Commit

Permalink
feat(nvim/mini|fzf)!: keep aligned w\ lazyvim upstream (#96)
Browse files Browse the repository at this point in the history
may introduce some breaking changes
i will solve them later
  • Loading branch information
andros21 authored Sep 29, 2024
1 parent df3c54c commit c28e1f5
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 30 deletions.
176 changes: 156 additions & 20 deletions nvim/.config/nvim/lua/andros21/plugins/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local util = require("andros21.util")

return {
"ibhagwan/fzf-lua",
cmd = "FzfLua",
dependencies = { "nvim-tree/nvim-web-devicons" },
keys = {
{ "<leader>,", "<cmd>FzfLua buffers<cr>", desc = "Switch Buffer" },
Expand Down Expand Up @@ -42,28 +43,163 @@ return {
{ "<leader>sw", util.fzflua("grep_cword"), desc = "Word (root dir)" },
{ "<leader>sW", util.fzflua("grep_cword", { cwd = false }), desc = "Word (cwd)" },
},
opts = {
previewers = {
git_diff = {
pager = "delta --width=$FZF_PREVIEW_COLUMNS",
opts = function(_, opts)
local config = require("fzf-lua.config")
local actions = require("fzf-lua.actions")

-- Quickfix
config.defaults.keymap.fzf["ctrl-q"] = "select-all+accept"
config.defaults.keymap.fzf["ctrl-u"] = "half-page-up"
config.defaults.keymap.fzf["ctrl-d"] = "half-page-down"
config.defaults.keymap.fzf["ctrl-x"] = "jump"
config.defaults.keymap.builtin["<c-f>"] = "preview-page-down"
config.defaults.keymap.builtin["<c-b>"] = "preview-page-up"

-- Trouble
if LazyVim.has("trouble.nvim") then
config.defaults.actions.files["ctrl-t"] = require("trouble.sources.fzf").actions.open
end

-- Toggle root dir / cwd
config.defaults.actions.files["ctrl-r"] = function(_, ctx)
local o = vim.deepcopy(ctx.__call_opts)
o.root = o.root == false
o.cwd = nil
o.buf = ctx.__CTX.bufnr
LazyVim.pick.open(ctx.__INFO.cmd, o)
end
config.defaults.actions.files["alt-c"] = config.defaults.actions.files["ctrl-r"]
config.set_action_helpstr(config.defaults.actions.files["ctrl-r"], "toggle-root-dir")

-- use the same prompt for all
local defaults = require("fzf-lua.profiles.default-title")
local function fix(t)
t.prompt = t.prompt ~= nil and "" or nil
for _, v in pairs(t) do
if type(v) == "table" then
fix(v)
end
end
end
fix(defaults)

local img_previewer ---@type string[]?
for _, v in ipairs({
{ cmd = "ueberzug", args = {} },
{ cmd = "chafa", args = { "{file}", "--format=symbols" } },
{ cmd = "viu", args = { "-b" } },
}) do
if vim.fn.executable(v.cmd) == 1 then
img_previewer = vim.list_extend({ v.cmd }, v.args)
break
end
end

return vim.tbl_deep_extend("force", defaults, {
fzf_colors = true,
fzf_opts = {
["--no-scrollbar"] = true,
},
},
git = {
status = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
defaults = {
-- formatter = "path.filename_first",
formatter = "path.dirname_first",
},
commits = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
previewers = {
git_diff = {
pager = "delta --width=$FZF_PREVIEW_COLUMNS",
},
builtin = {
extensions = {
["png"] = img_previewer,
["jpg"] = img_previewer,
["jpeg"] = img_previewer,
["gif"] = img_previewer,
["webp"] = img_previewer,
},
ueberzug_scaler = "fit_contain",
},
},
bcommits = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
-- Custom LazyVim option to configure vim.ui.select
ui_select = function(fzf_opts, items)
return vim.tbl_deep_extend("force", fzf_opts, {
prompt = "",
winopts = {
title = " " .. vim.trim((fzf_opts.prompt or "Select"):gsub("%s*:%s*$", "")) .. " ",
title_pos = "center",
},
}, fzf_opts.kind == "codeaction" and {
winopts = {
layout = "vertical",
-- height is number of items minus 15 lines for the preview, with a max of 80% screen height
height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
width = 0.5,
preview = {
layout = "vertical",
vertical = "down:15,border-top",
},
},
} or {
winopts = {
width = 0.5,
-- height is number of items, with a max of 80% screen height
height = math.floor(math.min(vim.o.lines * 0.8, #items + 2) + 0.5),
},
})
end,
winopts = {
width = 0.8,
height = 0.8,
row = 0.5,
col = 0.5,
preview = {
scrollchars = { "", "" },
},
},
},
files = {
fd_opts = "--color=never --type f --hidden --follow --exclude '{.git,.cache,.venv}'",
},
grep = {
rg_opts = "--column --line-number --no-heading --color=always --smart-case --max-columns=4096 --hidden --follow -g '!.git'",
},
},
git = {
status = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
},
commits = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
},
bcommits = {
preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
},
},
files = {
cwd_prompt = false,
fd_opts = "--color=never --type f --hidden --follow --exclude '{.git,.cache,.venv}'",
},
grep = {
rg_opts = "--column --line-number --no-heading --color=always --smart-case --max-columns=4096 --hidden --follow -g '!.git'",
},
lsp = {
symbols = {
symbol_hl = function(s)
return "TroubleIcon" .. s
end,
symbol_fmt = function(s)
return s:lower() .. "\t"
end,
child_prefix = false,
},
code_actions = {
previewer = vim.fn.executable("delta") == 1 and "codeaction_native" or nil,
},
},
})
end,
config = function(_, opts)
require("fzf-lua").setup(opts)
end,
init = function()
LazyVim.on_very_lazy(function()
vim.ui.select = function(...)
require("lazy").load({ plugins = { "fzf-lua" } })
local opts = LazyVim.opts("fzf-lua") or {}
require("fzf-lua").register_ui_select(opts.ui_select or nil)
return vim.ui.select(...)
end
end)
end,
}
53 changes: 43 additions & 10 deletions nvim/.config/nvim/lua/andros21/plugins/mini.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
-- ========
-- see:
-- * https://github.com/echasnovski/mini.nvim
-- * https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/util.lua
-- * https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/coding.lua

_G.LazyVim = require("lazyvim.util")

return {

{
Expand Down Expand Up @@ -36,21 +37,53 @@ return {
"echasnovski/mini.pairs",
event = "VeryLazy",
opts = {
mappings = {
["`"] = {
action = "closeopen",
pair = "``",
neigh_pattern = "[^\\`].",
register = { cr = false },
},
},
modes = { insert = true, command = true, terminal = false },
-- skip autopair when next character is one of these
skip_next = [=[[%w%%%'%[%"%.%`%$]]=],
-- skip autopair when the cursor is inside these treesitter nodes
skip_ts = { "string" },
-- skip autopair when next character is closing pair
-- and there are more closing pairs than opening pairs
skip_unbalanced = true,
-- better deal with markdown code blocks
markdown = true,
},
config = function(_, opts)
LazyVim.mini.pairs(opts)
end,
},

-- surround
{
"echasnovski/mini.surround",
opts = {},
keys = function(_, keys)
-- Populate the keys based on the user's options
local opts = LazyVim.opts("mini.surround")
local mappings = {
{ opts.mappings.add, desc = "Add Surrounding", mode = { "n", "v" } },
{ opts.mappings.delete, desc = "Delete Surrounding" },
{ opts.mappings.find, desc = "Find Right Surrounding" },
{ opts.mappings.find_left, desc = "Find Left Surrounding" },
{ opts.mappings.highlight, desc = "Highlight Surrounding" },
{ opts.mappings.replace, desc = "Replace Surrounding" },
{ opts.mappings.update_n_lines, desc = "Update `MiniSurround.config.n_lines`" },
}
mappings = vim.tbl_filter(function(m)
return m[1] and #m[1] > 0
end, mappings)
return vim.list_extend(mappings, keys)
end,
opts = {
mappings = {
add = "gsa", -- Add surrounding in Normal and Visual modes
delete = "gsd", -- Delete surrounding
find = "gsf", -- Find surrounding (to the right)
find_left = "gsF", -- Find surrounding (to the left)
highlight = "gsh", -- Highlight surrounding
replace = "gsr", -- Replace surrounding
update_n_lines = "gsn", -- Update `n_lines`
},
},
},

-- comment
Expand Down

0 comments on commit c28e1f5

Please sign in to comment.