From f24999fd3645756a338137278ccc4fa3e1240a90 Mon Sep 17 00:00:00 2001 From: xiaojianzheng <1272209235@qq.com> Date: Sun, 16 Jun 2024 13:21:30 +0800 Subject: [PATCH] feat(project): add some fzf-lua keymap (#3666) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `ctrl-s` search_in_project_files - `ctrl-w` change_working_directory - `ctrl-d` delete_project - `ctrl-r` recent_project_files Co-authored-by: 肖健正 --- lua/lazyvim/plugins/extras/util/project.lua | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/util/project.lua b/lua/lazyvim/plugins/extras/util/project.lua index 7a391c6a..c84b73bb 100644 --- a/lua/lazyvim/plugins/extras/util/project.lua +++ b/lua/lazyvim/plugins/extras/util/project.lua @@ -1,11 +1,15 @@ -local pick = function() +local pick = nil + +pick = function() if LazyVim.pick.picker.name == "telescope" then return vim.cmd("Telescope projects") elseif LazyVim.pick.picker.name == "fzf" then local fzf_lua = require("fzf-lua") + local project = require("project_nvim.project") local history = require("project_nvim.utils.history") local results = history.get_recent_projects() local actions = require("fzf-lua.actions") + fzf_lua.fzf_exec(results, { actions = { ["default"] = { @@ -14,6 +18,34 @@ local pick = function() end, }, ["ctrl-t"] = actions.file_tabedit, + ["ctrl-s"] = { + function(selected) + fzf_lua.live_grep({ cwd = selected[1] }) + end, + }, + ["ctrl-r"] = { + function(selected) + fzf_lua.oldfiles({ cwd = selected[1] }) + end, + }, + ["ctrl-w"] = { + function(selected) + local path = selected[1] + local ok = project.set_pwd(path) + if ok then + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) + LazyVim.info("Change project dir to " .. path) + end + end, + }, + ["ctrl-d"] = function(selected) + local path = selected[1] + local choice = vim.fn.confirm("Delete '" .. path .. "' project? ", "&Yes\n&No") + if choice == 1 then + history.delete_project({ value = path }) + end + pick() + end, }, }) end