diff --git a/nvim/lua/config/keys.lua b/nvim/lua/config/keys.lua index 6c381ce..7b839d4 100644 --- a/nvim/lua/config/keys.lua +++ b/nvim/lua/config/keys.lua @@ -4,38 +4,87 @@ local M = {} ---@type KeymapDefinition[] M.keymaps = { - -- telescope keymaps + -- picker keymaps + { + mode = "n", + keys = "ex", + command = function() require("snacks").picker.explorer() end, + opts = { desc = "Snacks file explorer" }, + }, { mode = "n", keys = "ff", - command = function() require("telescope.builtin").find_files() end, + command = function() require("snacks").picker.files() end, opts = { desc = "Fuzzy find files" }, }, { mode = "n", keys = "fF", - command = function() require("telescope.builtin").git_files() end, + command = function() require("snacks").picker.git_files() end, opts = { desc = "Fuzzy find files (git files)" }, }, { mode = "n", keys = "fg", - command = function() require("telescope.builtin").live_grep() end, + command = function() require("snacks").picker.grep() end, opts = { desc = "Fuzzy live grep" }, }, { mode = "n", keys = "fb", - command = function() require("telescope.builtin").buffers() end, + command = function() require("snacks").picker.buffers() end, opts = { desc = "Fuzzy find buffers" }, }, { mode = "n", keys = "fh", - command = function() require("telescope.builtin").help_tags() end, + command = function() require("snacks").picker.help() end, opts = { desc = "Fuzzy find help tags" }, }, - + -- lsp keymaps + { + mode = "n", + keys = "gd", + command = function() require("snacks").picker.lsp_definitions() end, + opts = { desc = "Goto Definition" }, + }, + { + mode = "n", + keys = "gD", + command = function() require("snacks").picker.lsp_declarations() end, + opts = { desc = "Goto Declaration" }, + }, + { + mode = "n", + keys = "gr", + command = function() require("snacks").picker.lsp_references() end, + nowait = true, + opts = { desc = "References" }, + }, + { + mode = "n", + keys = "gI", + command = function() require("snacks").picker.lsp_implementations() end, + opts = { desc = "Goto Implementation" }, + }, + { + mode = "n", + keys = "gy", + command = function() require("snacks").picker.lsp_type_definitions() end, + opts = { desc = "Goto T[y]pe Definition" }, + }, + { + mode = "n", + keys = "ss", + command = function() require("snacks").picker.lsp_symbols() end, + opts = { desc = "LSP Symbols" }, + }, + { + mode = "n", + keys = "sS", + command = function() require("snacks").picker.lsp_workspace_symbols() end, + opts = { desc = "LSP Workspace Symbols" }, + }, -- gitsigns { mode = "n", diff --git a/nvim/lua/core/configs/alpha.lua b/nvim/lua/core/configs/alpha.lua index 636a84e..6d1d5be 100644 --- a/nvim/lua/core/configs/alpha.lua +++ b/nvim/lua/core/configs/alpha.lua @@ -4,9 +4,9 @@ local dashboard = require("alpha.themes.dashboard") -- Set menu dashboard.section.buttons.val = { dashboard.button("e", " > New file", ":ene startinsert "), - dashboard.button("f", " > Find file", ":Telescope find_files"), - dashboard.button("g", " > Find string", ":Telescope live_grep"), - dashboard.button("r", " > Recent", ":Telescope oldfiles"), + dashboard.button("f", " > Find file", ":lua Snacks.picker.files()"), + dashboard.button("g", " > Find string", ":lua Snacks.picker.grep()"), + dashboard.button("r", " > Recent", ":lua Snacks.picker.recent()"), dashboard.button("q", " > Quit NVIM", ":qa"), } diff --git a/nvim/lua/core/configs/scrollbar.lua b/nvim/lua/core/configs/scrollbar.lua index 0cd688b..7d081ea 100644 --- a/nvim/lua/core/configs/scrollbar.lua +++ b/nvim/lua/core/configs/scrollbar.lua @@ -114,7 +114,6 @@ require("scrollbar").setup({ "cmp_menu", "noice", "prompt", - "TelescopePrompt", }, autocmd = { render = { diff --git a/nvim/lua/core/configs/snacks.lua b/nvim/lua/core/configs/snacks.lua index c8be766..4dde70e 100644 --- a/nvim/lua/core/configs/snacks.lua +++ b/nvim/lua/core/configs/snacks.lua @@ -1,13 +1,15 @@ +local picker_config = require("core.configs.snacks_picker") + require("snacks").setup( ---@type snacks.Config { bigfile = { enabled = true }, dashboard = { enabled = false }, - explorer = { enabled = false }, + explorer = { enabled = true, replace_netrw = true }, image = { enabled = false }, indent = { enabled = true }, input = { enabled = false }, - picker = { enabled = false }, + picker = picker_config, notifier = { enabled = false }, quickfile = { enabled = true }, scope = { enabled = true }, diff --git a/nvim/lua/core/configs/snacks_picker.lua b/nvim/lua/core/configs/snacks_picker.lua new file mode 100644 index 0000000..abe7fb8 --- /dev/null +++ b/nvim/lua/core/configs/snacks_picker.lua @@ -0,0 +1,325 @@ +---@class snacks.picker.Config +return { + enabled = true, + prompt = " ", + sources = {}, + focus = "input", + layout = { + cycle = true, + --- Use the default layout or vertical if the window is too narrow + preset = function() return vim.o.columns >= 120 and "default" or "vertical" end, + }, + ---@class snacks.picker.matcher.Config + matcher = { + fuzzy = true, -- use fuzzy matching + smartcase = true, -- use smartcase + ignorecase = true, -- use ignorecase + sort_empty = false, -- sort results when the search string is empty + filename_bonus = true, -- give bonus for matching file names (last part of the path) + file_pos = true, -- support patterns like `file:line:col` and `file:line` + -- the bonusses below, possibly require string concatenation and path normalization, + -- so this can have a performance impact for large lists and increase memory usage + cwd_bonus = false, -- give bonus for matching files in the cwd + frecency = false, -- frecency bonus + history_bonus = false, -- give more weight to chronological order + }, + sort = { + -- default sort is by score, text length and index + fields = { "score:desc", "#text", "idx" }, + }, + ui_select = true, -- replace `vim.ui.select` with the snacks picker + ---@class snacks.picker.formatters.Config + formatters = { + text = { + ft = nil, ---@type string? filetype for highlighting + }, + file = { + filename_first = false, -- display filename before the file path + truncate = 40, -- truncate the file path to (roughly) this length + filename_only = false, -- only show the filename + icon_width = 2, -- width of the icon (in characters) + git_status_hl = true, -- use the git status highlight group for the filename + }, + selected = { + show_always = false, -- only show the selected column when there are multiple selections + unselected = true, -- use the unselected icon for unselected items + }, + severity = { + icons = true, -- show severity icons + level = false, -- show severity level + ---@type "left"|"right" + pos = "left", -- position of the diagnostics + }, + }, + ---@class snacks.picker.previewers.Config + previewers = { + diff = { + builtin = true, -- use Neovim for previewing diffs (true) or use an external tool (false) + cmd = { "delta" }, -- example to show a diff with delta + }, + git = { + builtin = true, -- use Neovim for previewing git output (true) or use git (false) + args = {}, -- additional arguments passed to the git command. Useful to set pager options usin `-c ...` + }, + file = { + max_size = 1024 * 1024, -- 1MB + max_line_length = 500, -- max line length + ft = nil, ---@type string? filetype for highlighting. Use `nil` for auto detect + }, + man_pager = nil, ---@type string? MANPAGER env to use for `man` preview + }, + ---@class snacks.picker.jump.Config + jump = { + jumplist = true, -- save the current position in the jumplist + tagstack = false, -- save the current position in the tagstack + reuse_win = false, -- reuse an existing window if the buffer is already open + close = true, -- close the picker when jumping/editing to a location (defaults to true) + match = false, -- jump to the first match position. (useful for `lines`) + }, + toggles = { + follow = "f", + hidden = "h", + ignored = "i", + modified = "m", + regex = { icon = "R", value = false }, + }, + win = { + -- input window + input = { + keys = { + -- to close the picker on ESC instead of going to normal mode, + -- add the following keymap to your config + -- [""] = { "close", mode = { "n", "i" } }, + ["/"] = "toggle_focus", + [""] = { "history_forward", mode = { "i", "n" } }, + [""] = { "history_back", mode = { "i", "n" } }, + [""] = { "cancel", mode = "i" }, + [""] = { + "", + mode = { "i" }, + expr = true, + desc = "delete word", + }, + [""] = { "confirm", mode = { "n", "i" } }, + [""] = { "list_down", mode = { "i", "n" } }, + [""] = "cancel", + [""] = { { "pick_win", "jump" }, mode = { "n", "i" } }, + [""] = { "select_and_prev", mode = { "i", "n" } }, + [""] = { "select_and_next", mode = { "i", "n" } }, + [""] = { "list_up", mode = { "i", "n" } }, + [""] = { "inspect", mode = { "n", "i" } }, + [""] = { "toggle_follow", mode = { "i", "n" } }, + [""] = { "toggle_hidden", mode = { "i", "n" } }, + [""] = { "toggle_ignored", mode = { "i", "n" } }, + [""] = { "toggle_maximize", mode = { "i", "n" } }, + [""] = { "toggle_preview", mode = { "i", "n" } }, + [""] = { "cycle_win", mode = { "i", "n" } }, + [""] = { "select_all", mode = { "n", "i" } }, + [""] = { "preview_scroll_up", mode = { "i", "n" } }, + [""] = { "list_scroll_down", mode = { "i", "n" } }, + [""] = { "preview_scroll_down", mode = { "i", "n" } }, + [""] = { "toggle_live", mode = { "i", "n" } }, + [""] = { "list_down", mode = { "i", "n" } }, + [""] = { "list_up", mode = { "i", "n" } }, + [""] = { "list_down", mode = { "i", "n" } }, + [""] = { "list_up", mode = { "i", "n" } }, + [""] = { "qflist", mode = { "i", "n" } }, + [""] = { "edit_split", mode = { "i", "n" } }, + [""] = { "tab", mode = { "n", "i" } }, + [""] = { "list_scroll_up", mode = { "i", "n" } }, + [""] = { "edit_vsplit", mode = { "i", "n" } }, + ["#"] = { "insert_alt", mode = "i" }, + ["%"] = { "insert_filename", mode = "i" }, + [""] = { "insert_cWORD", mode = "i" }, + [""] = { "insert_file", mode = "i" }, + [""] = { "insert_line", mode = "i" }, + [""] = { "insert_file_full", mode = "i" }, + [""] = { "insert_cword", mode = "i" }, + ["H"] = "layout_left", + ["J"] = "layout_bottom", + ["K"] = "layout_top", + ["L"] = "layout_right", + ["?"] = "toggle_help_input", + ["G"] = "list_bottom", + ["gg"] = "list_top", + ["j"] = "list_down", + ["k"] = "list_up", + ["q"] = "close", + }, + b = { + minipairs_disable = true, + }, + }, + -- result list window + list = { + keys = { + ["/"] = "toggle_focus", + ["<2-LeftMouse>"] = "confirm", + [""] = "confirm", + [""] = "list_down", + [""] = "cancel", + [""] = { { "pick_win", "jump" } }, + [""] = { "select_and_prev", mode = { "n", "x" } }, + [""] = { "select_and_next", mode = { "n", "x" } }, + [""] = "list_up", + [""] = "inspect", + [""] = "toggle_follow", + [""] = "toggle_hidden", + [""] = "toggle_ignored", + [""] = "toggle_maximize", + [""] = "toggle_preview", + [""] = "cycle_win", + [""] = "select_all", + [""] = "preview_scroll_up", + [""] = "list_scroll_down", + [""] = "preview_scroll_down", + [""] = "list_down", + [""] = "list_up", + [""] = "list_down", + [""] = "list_up", + [""] = "qflist", + [""] = "edit_split", + [""] = "tab", + [""] = "list_scroll_up", + [""] = "edit_vsplit", + ["H"] = "layout_left", + ["J"] = "layout_bottom", + ["K"] = "layout_top", + ["L"] = "layout_right", + ["?"] = "toggle_help_list", + ["G"] = "list_bottom", + ["gg"] = "list_top", + ["i"] = "focus_input", + ["j"] = "list_down", + ["k"] = "list_up", + ["q"] = "close", + ["zb"] = "list_scroll_bottom", + ["zt"] = "list_scroll_top", + ["zz"] = "list_scroll_center", + }, + wo = { + conceallevel = 2, + concealcursor = "nvc", + }, + }, + -- preview window + preview = { + keys = { + [""] = "cancel", + ["q"] = "close", + ["i"] = "focus_input", + [""] = "cycle_win", + }, + }, + }, + ---@class snacks.picker.icons + icons = { + files = { + enabled = true, -- show file icons + dir = "󰉋 ", + dir_open = "󰝰 ", + file = "󰈔 ", + }, + keymaps = { + nowait = "󰓅 ", + }, + tree = { + vertical = "│ ", + middle = "├╴", + last = "└╴", + }, + undo = { + saved = " ", + }, + ui = { + live = "󰐰 ", + hidden = "h", + ignored = "i", + follow = "f", + selected = "● ", + unselected = "○ ", + -- selected = " ", + }, + git = { + enabled = true, -- show git icons + commit = "󰜘 ", -- used by git log + staged = "●", -- staged changes. always overrides the type icons + added = "", + deleted = "", + ignored = " ", + modified = "○", + renamed = "", + unmerged = " ", + untracked = "?", + }, + diagnostics = { + Error = " ", + Warn = " ", + Hint = " ", + Info = " ", + }, + lsp = { + unavailable = "", + enabled = " ", + disabled = " ", + attached = "󰖩 ", + }, + kinds = { + Array = " ", + Boolean = "󰨙 ", + Class = " ", + Color = " ", + Control = " ", + Collapsed = " ", + Constant = "󰏿 ", + Constructor = " ", + Copilot = " ", + Enum = " ", + EnumMember = " ", + Event = " ", + Field = " ", + File = " ", + Folder = " ", + Function = "󰊕 ", + Interface = " ", + Key = " ", + Keyword = " ", + Method = "󰊕 ", + Module = " ", + Namespace = "󰦮 ", + Null = " ", + Number = "󰎠 ", + Object = " ", + Operator = " ", + Package = " ", + Property = " ", + Reference = " ", + Snippet = "󱄽 ", + String = " ", + Struct = "󰆼 ", + Text = " ", + TypeParameter = " ", + Unit = " ", + Unknown = " ", + Value = " ", + Variable = "󰀫 ", + }, + }, + ---@class snacks.picker.db.Config + db = { + -- path to the sqlite3 library + -- If not set, it will try to load the library by name. + -- On Windows it will download the library from the internet. + sqlite3_path = nil, ---@type string? + }, + ---@class snacks.picker.debug + debug = { + scores = false, -- show scores in the list + leaks = false, -- show when pickers don't get garbage collected + explorer = false, -- show explorer debug info + files = false, -- show file debug info + grep = false, -- show file debug info + proc = false, -- show proc debug info + extmarks = false, -- show extmarks errors + }, +} diff --git a/nvim/lua/core/configs/telescope.lua b/nvim/lua/core/configs/telescope.lua deleted file mode 100644 index e87bbcd..0000000 --- a/nvim/lua/core/configs/telescope.lua +++ /dev/null @@ -1,56 +0,0 @@ -require("telescope").setup({ - - defaults = { - mappings = { - i = { - [""] = function(prompt_bufnr) - -- Use nvim-window-picker to choose the window by dynamically attaching a function - local action_set = require("telescope.actions.set") - local action_state = require("telescope.actions.state") - - local picker = action_state.get_current_picker(prompt_bufnr) - picker.get_selection_window = function(picker, entry) - local picked_window_id = require("window-picker").pick_window() - or vim.api.nvim_get_current_win() - -- Unbind after using so next instance of the picker acts normally - picker.get_selection_window = nil - return picked_window_id - end - - return action_set.edit(prompt_bufnr, "edit") - end, - }, - }, - }, - extensions = { - lsp_handlers = { - disable = {}, - location = { - telescope = {}, - no_results_message = "No references found", - }, - symbol = { - telescope = {}, - no_results_message = "No symbols found", - }, - call_hierarchy = { - telescope = {}, - no_results_message = "No calls found", - }, - code_action = { - telescope = require("telescope.themes").get_dropdown({}), - no_results_message = "No code actions available", - prefix = "", - }, - }, - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - }, - }, -}) - -require("telescope").load_extension("fzf") -require("telescope").load_extension("lsp_handlers") diff --git a/nvim/lua/core/plugins.lua b/nvim/lua/core/plugins.lua index 7b5c705..48da3c8 100644 --- a/nvim/lua/core/plugins.lua +++ b/nvim/lua/core/plugins.lua @@ -53,28 +53,6 @@ local plugins = { event = "VeryLazy", }, - -- telescope - { - "nvim-telescope/telescope.nvim", - event = "VeryLazy", - dependencies = { - "gbrlsnchs/telescope-lsp-handlers.nvim", - { - "nvim-telescope/telescope-fzf-native.nvim", - build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build", - }, - }, - config = function() require("core.configs.telescope") end, - }, - - { - "s1n7ax/nvim-window-picker", - name = "window-picker", - event = "VeryLazy", - version = "2.*", - config = function() require("core.configs.winpick") end, - }, - -- gitsigns - git tools { "lewis6991/gitsigns.nvim",