feat(plugins): switch to fff for find/grep and enhance keymaps
This commit is contained in:
1 parent
6b8a1ec910
commit
8f49f66837
2 files changed
+41
-21
No files matched your search
+40
-20
@@ -20,8 +20,8 @@ end
|
|||||||
|
|
||||||
-- <C-f>e: two-stage find-by-extension. Stage 1 scans the repo with fd
|
-- <C-f>e: two-stage find-by-extension. Stage 1 scans the repo with fd
|
||||||
-- (respects .gitignore) and shows every file extension ranked by count;
|
-- (respects .gitignore) and shows every file extension ranked by count;
|
||||||
-- stage 2 opens the regular files picker restricted to the chosen
|
-- stage 2 opens fff prefilled with a `*.<ext> ` glob constraint so the
|
||||||
-- extension (snacks passes `ft` to fd as `-e`).
|
-- rest of the query fuzzy-matches within that extension.
|
||||||
local function find_files_by_extension()
|
local function find_files_by_extension()
|
||||||
local snacks = require "snacks"
|
local snacks = require "snacks"
|
||||||
local root = snacks.git.get_root() or vim.uv.cwd()
|
local root = snacks.git.get_root() or vim.uv.cwd()
|
||||||
@@ -61,7 +61,7 @@ local function find_files_by_extension()
|
|||||||
confirm = function(picker, item)
|
confirm = function(picker, item)
|
||||||
picker:close()
|
picker:close()
|
||||||
if not item then return end
|
if not item then return end
|
||||||
snacks.picker.files { cwd = root, ft = item.ext, transform = file_filter }
|
require("fff").find_files { cwd = root, title = "*." .. item.ext .. " files", query = "*." .. item.ext .. " " }
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -281,18 +281,40 @@ return {
|
|||||||
function() require("snacks").picker.lines() end,
|
function() require("snacks").picker.lines() end,
|
||||||
desc = "Find in line",
|
desc = "Find in line",
|
||||||
},
|
},
|
||||||
["<C-f>t"] = {
|
-- NOTE: <C-i> and <Tab> are the same key at the mapping level, so
|
||||||
|
-- this also shadows <Tab> (jumplist-forward) in normal mode
|
||||||
|
["<C-i>"] = {
|
||||||
function() require("config.templates").pick() end,
|
function() require("config.templates").pick() end,
|
||||||
desc = "Find templates",
|
desc = "Find templates",
|
||||||
},
|
},
|
||||||
["<C-f>w"] = {
|
["<C-f>w"] = {
|
||||||
function() require("snacks").picker.grep() end,
|
function() require("fff").live_grep() end,
|
||||||
desc = "Find word",
|
desc = "Live grep",
|
||||||
|
},
|
||||||
|
["<C-f>z"] = {
|
||||||
|
function() require("fff").live_grep { grep = { modes = { "fuzzy", "plain" } } } end,
|
||||||
|
desc = "Live fuzzy grep",
|
||||||
|
},
|
||||||
|
["<C-f><C-w>"] = {
|
||||||
|
function() require("fff").live_grep_under_cursor() end,
|
||||||
|
desc = "Grep word under cursor",
|
||||||
},
|
},
|
||||||
["<C-f>f"] = {
|
["<C-f>f"] = {
|
||||||
function() require("snacks").picker.files { transform = file_filter } end,
|
function() require("fff").find_files() end,
|
||||||
desc = "Find files (cwd)",
|
desc = "Find files (cwd)",
|
||||||
},
|
},
|
||||||
|
["<C-f>m"] = {
|
||||||
|
function() require("fff").find_files { title = "Git Modified", query = "git:modified " } end,
|
||||||
|
desc = "Find git-modified files",
|
||||||
|
},
|
||||||
|
["<C-f>r"] = {
|
||||||
|
function() require("fff").resume() end,
|
||||||
|
desc = "Resume last find/grep",
|
||||||
|
},
|
||||||
|
["<C-f>."] = {
|
||||||
|
function() require("fff").find_files_in_dir(vim.fn.expand "%:p:h") end,
|
||||||
|
desc = "Find files in buffer directory",
|
||||||
|
},
|
||||||
["<C-f>e"] = {
|
["<C-f>e"] = {
|
||||||
find_files_by_extension,
|
find_files_by_extension,
|
||||||
desc = "Find files by extension",
|
desc = "Find files by extension",
|
||||||
@@ -318,10 +340,7 @@ return {
|
|||||||
vim.notify("No .ai directory found in current project", vim.log.levels.WARN)
|
vim.notify("No .ai directory found in current project", vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
require("snacks").picker.files {
|
require("fff").find_files_in_dir(ai_dir)
|
||||||
cwd = ai_dir,
|
|
||||||
transform = file_filter,
|
|
||||||
}
|
|
||||||
end,
|
end,
|
||||||
desc = "Find AI files",
|
desc = "Find AI files",
|
||||||
},
|
},
|
||||||
@@ -333,28 +352,25 @@ return {
|
|||||||
vim.notify("No .github/workflows directory found in current project", vim.log.levels.WARN)
|
vim.notify("No .github/workflows directory found in current project", vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
require("snacks").picker.files {
|
require("fff").find_files_in_dir(workflows_dir)
|
||||||
cwd = workflows_dir,
|
|
||||||
transform = file_filter,
|
|
||||||
}
|
|
||||||
end,
|
end,
|
||||||
desc = "Find GitHub Workflow files",
|
desc = "Find GitHub Workflow files",
|
||||||
},
|
},
|
||||||
["<C-f>gd"] = {
|
["<C-f>gd"] = {
|
||||||
function()
|
function()
|
||||||
require("snacks").picker.files {
|
require("fff").find_files {
|
||||||
cmd = "fd",
|
title = "Devbox/Docker files",
|
||||||
args = { "devbox.json|process-compose.yaml|Dockerfile|docker-compose.yaml|compose.yaml" },
|
query = "{devbox.json,process-compose.yaml,Dockerfile,docker-compose.yaml,compose.yaml} ",
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
desc = "Find Devbox/Docker files",
|
desc = "Find Devbox/Docker files",
|
||||||
},
|
},
|
||||||
["<C-f>gm"] = {
|
["<C-f>gm"] = {
|
||||||
function() require("snacks").picker.files { cmd = "fd", args = { "Makefile" } } end,
|
function() require("fff").find_files { title = "Makefiles", query = "*Makefile* " } end,
|
||||||
desc = "Find Makefile files",
|
desc = "Find Makefile files",
|
||||||
},
|
},
|
||||||
["<C-f>gp"] = {
|
["<C-f>gp"] = {
|
||||||
function() require("snacks").picker.files { cmd = "fd", args = { "package.json" } } end,
|
function() require("fff").find_files { title = "package.json files", query = "*package.json " } end,
|
||||||
desc = "Find Package.json files",
|
desc = "Find Package.json files",
|
||||||
},
|
},
|
||||||
["<C-p>"] = {
|
["<C-p>"] = {
|
||||||
@@ -477,6 +493,10 @@ return {
|
|||||||
v = {
|
v = {
|
||||||
["<C-c>"] = { "<Cmd>w<CR><Cmd>bd<CR>", desc = "Save and close buffer" },
|
["<C-c>"] = { "<Cmd>w<CR><Cmd>bd<CR>", desc = "Save and close buffer" },
|
||||||
["<C-x>"] = { "<Cmd>w<CR><Cmd>bd<CR>", desc = "Save and close buffer" },
|
["<C-x>"] = { "<Cmd>w<CR><Cmd>bd<CR>", desc = "Save and close buffer" },
|
||||||
|
["<C-f><C-w>"] = {
|
||||||
|
function() require("fff").live_grep_under_cursor() end,
|
||||||
|
desc = "Grep selection",
|
||||||
|
},
|
||||||
["D"] = {
|
["D"] = {
|
||||||
function()
|
function()
|
||||||
vim.cmd 'normal! "vy'
|
vim.cmd 'normal! "vy'
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ return {
|
|||||||
width = 32,
|
width = 32,
|
||||||
-- window option, not a top level one (it used to be set top level,
|
-- window option, not a top level one (it used to be set top level,
|
||||||
-- where neo-tree ignored it)
|
-- where neo-tree ignored it)
|
||||||
auto_expand_width = true,
|
auto_expand_width = false,
|
||||||
-- keys must be spelled exactly like neo-tree's own defaults:
|
-- keys must be spelled exactly like neo-tree's own defaults:
|
||||||
-- setup() does not case-normalize them, so `<CR>` would sit next to
|
-- setup() does not case-normalize them, so `<CR>` would sit next to
|
||||||
-- the default `<cr>` and whichever `pairs()` reached last would win
|
-- the default `<cr>` and whichever `pairs()` reached last would win
|
||||||
|
|||||||
Reference in new issue
Block a user