From 93c06cd954e7a73cc3fad0799ab49f1a1fc10d73 Mon Sep 17 00:00:00 2001 From: Charles Chiu Date: Thu, 20 Jun 2024 09:39:21 +0800 Subject: [PATCH] Feat/telescope collections keymaps (#1299) * feat(telescope): add some new plugins for `search.nvim` * fixup: correct alpha-nvim config. * feat: more resonable keymap, add notify to misc. Signed-off-by: ayamir --------- Signed-off-by: ayamir Co-authored-by: ayamir --- lua/keymap/tool.lua | 38 +++++++++- lua/modules/configs/completion/cmp.lua | 35 ++++------ lua/modules/configs/tool/search.lua | 26 ++++--- lua/modules/configs/ui/alpha.lua | 97 +++++++++++++------------- lua/modules/utils/icons.lua | 2 + 5 files changed, 120 insertions(+), 78 deletions(-) diff --git a/lua/keymap/tool.lua b/lua/keymap/tool.lua index bd928f082..7e76cd8e3 100644 --- a/lua/keymap/tool.lua +++ b/lua/keymap/tool.lua @@ -84,12 +84,46 @@ local plug_map = { :with_noremap() :with_silent() :with_desc("tool: Toggle command panel"), - ["n|f"] = map_callback(function() + ["n|fc"] = map_callback(function() _telescope_collections(require("telescope.themes").get_dropdown()) end) :with_noremap() :with_silent() - :with_desc("tool: Open Telescope"), + :with_desc("tool: Open Telescope (collections)"), + ["n|ff"] = map_callback(function() + require("search").open({ collection = "file" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (file)"), + ["n|fw"] = map_callback(function() + require("search").open({ collection = "word" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (word)"), + ["v|fs"] = map_cu("Telescope grep_string") + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (selected)"), + ["n|fg"] = map_callback(function() + require("search").open({ collection = "git" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (git)"), + ["n|fr"] = map_callback(function() + require("search").open({ collection = "rootdir" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (rootdir)"), + ["n|fm"] = map_callback(function() + require("search").open({ collection = "misc" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope (misc)"), -- Plugin: dap ["n|"] = map_callback(function() diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index 0d926e0ee..7e6c14cf0 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -162,28 +162,23 @@ return function() { name = "nvim_lsp", max_item_count = 350 }, { name = "nvim_lua" }, { name = "luasnip" }, - { name = "path" }, - { name = "treesitter" }, - { name = "spell" }, - { name = "tmux" }, - { name = "orgmode" }, - { - name = "buffer", - option = { - get_bufnrs = function() - return vim.api.nvim_list_bufs() - end, - }, - }, - { name = "latex_symbols" }, - { name = "copilot" }, + -- { name = "path" }, + -- { name = "treesitter" }, + -- { name = "spell" }, + -- { name = "tmux" }, + -- { name = "orgmode" }, + -- { + -- name = "buffer", + -- option = { + -- get_bufnrs = function() + -- return vim.api.nvim_list_bufs() + -- end, + -- }, + -- }, + -- { name = "latex_symbols" }, + -- { name = "copilot" }, -- { name = "codeium" }, -- { name = "cmp_tabnine" }, }, - experimental = { - ghost_text = { - hl_group = "Whitespace", - }, - }, }) end diff --git a/lua/modules/configs/tool/search.lua b/lua/modules/configs/tool/search.lua index e01f50437..a81726082 100644 --- a/lua/modules/configs/tool/search.lua +++ b/lua/modules/configs/tool/search.lua @@ -4,6 +4,7 @@ return function() require("modules.utils").load_plugin("search", { collections = { + -- Search by file name file = { initial_tab = 1, tabs = { @@ -30,9 +31,16 @@ return function() builtin.oldfiles() end, }, + { + name = "Buffers", + tele_func = function() + builtin.buffers() + end, + }, }, }, - live_grep = { + -- Search by word + word = { initial_tab = 1, tabs = { { @@ -50,6 +58,7 @@ return function() }, }, }, + -- Search by git (branches, commits) git = { initial_tab = 1, tabs = { @@ -79,15 +88,10 @@ return function() }, }, }, - workspace = { + -- Search by rootdir name + rootdir = { initial_tab = 1, tabs = { - { - name = "Buffers", - tele_func = function() - builtin.buffers() - end, - }, { name = "Sessions", tele_func = function() @@ -117,6 +121,12 @@ return function() builtin.colorscheme({ enable_preview = true }) end, }, + { + name = "Notify", + tele_func = function() + extensions.notify.notify() + end, + }, { name = "Undo History", tele_func = function() diff --git a/lua/modules/configs/ui/alpha.lua b/lua/modules/configs/ui/alpha.lua index 73a489c12..d50310d81 100644 --- a/lua/modules/configs/ui/alpha.lua +++ b/lua/modules/configs/ui/alpha.lua @@ -39,55 +39,56 @@ return function() end local leader = " " + local icons = { + documents = require("modules.utils.icons").get("documents", true), + git = require("modules.utils.icons").get("git", true), + ui = require("modules.utils.icons").get("ui", true), + misc = require("modules.utils.icons").get("misc", true), + } + dashboard.section.buttons.val = { - button("space f c", " Scheme change", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope.builtin").colorscheme() - end, - }), - button("space f r", " File frecency", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope").extensions.frecency.frecency({}) - end, - }), - button("space f e", "󰋚 File history", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope.builtin").oldfiles() - end, - }), - button("space f p", " Project find", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope").extensions.projects.projects({}) - end, - }), - button("space f f", "󰈞 File find", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope.builtin").find_files() - end, - }), - button("space f w", " Word find", leader, nil, { - noremap = true, - silent = true, - nowait = true, - callback = function() - require("telescope.builtin").live_grep() - end, - }), + button( + "space f c", + icons.misc.Neovim .. "Telescope collections", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), + button( + "space f g", + icons.git.Git .. "Telescope git", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), + button( + "space f w", + icons.ui.FolderWithHeart .. "Telescope workspace", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), + button( + "space f f", + icons.documents.FileFind .. "Telescope file", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), + button( + "space f l", + icons.documents.Word .. "Telescope live_grep", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), + button( + "space f m", + icons.misc.Ghost .. "Telescope misc", + leader, + nil, + { noremap = true, silent = true, nowait = true } + ), } dashboard.section.buttons.opts.hl = "AlphaButtons" diff --git a/lua/modules/utils/icons.lua b/lua/modules/utils/icons.lua index eab8da2c7..60acedbbc 100644 --- a/lua/modules/utils/icons.lua +++ b/lua/modules/utils/icons.lua @@ -63,6 +63,8 @@ local data = { File = "", Files = "", FileTree = "󰙅", + FileFind = "󰈞", + Word = "", Import = "", Symlink = "", },