From 8f70ecd882cf44567ddbffb469373501492938f9 Mon Sep 17 00:00:00 2001 From: LostNeophyte Date: Sat, 18 Feb 2023 08:55:05 +0100 Subject: refactor(builtins): move builtins to lvim/builtin --- lua/lvim/builtin/which-key.lua | 320 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 lua/lvim/builtin/which-key.lua (limited to 'lua/lvim/builtin/which-key.lua') diff --git a/lua/lvim/builtin/which-key.lua b/lua/lvim/builtin/which-key.lua new file mode 100644 index 00000000..70a24a27 --- /dev/null +++ b/lua/lvim/builtin/which-key.lua @@ -0,0 +1,320 @@ +local M = {} +M.config = function() + lvim.builtin.which_key = { + ---@usage disable which-key completely [not recommended] + active = true, + setup = { + plugins = { + marks = false, -- shows a list of your marks on ' and ` + registers = false, -- shows your registers on " in NORMAL or in INSERT mode + spelling = { + enabled = true, + suggestions = 20, + }, -- use which-key for spelling hints + -- the presets plugin, adds help for a bunch of default keybindings in Neovim + -- No actual key bindings are created + presets = { + operators = false, -- adds help for operators like d, y, ... + motions = false, -- adds help for motions + text_objects = false, -- help for text objects triggered after entering an operator + windows = false, -- default bindings on + nav = false, -- misc bindings to work with windows + z = false, -- bindings for folds, spelling and others prefixed with z + g = false, -- bindings for prefixed with g + }, + }, + -- add operators that will trigger motion and text object completion + -- to enable all native operators, set the preset / operators plugin above + operators = { gc = "Comments" }, + key_labels = { + -- override the label used to display some keys. It doesn't effect WK in any other way. + -- For example: + -- [""] = "SPC", + -- [""] = "RET", + -- [""] = "TAB", + }, + icons = { + breadcrumb = lvim.icons.ui.DoubleChevronRight, -- symbol used in the command line area that shows your active key combo + separator = lvim.icons.ui.BoldArrowRight, -- symbol used between a key and it's label + group = lvim.icons.ui.Plus, -- symbol prepended to a group + }, + popup_mappings = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + window = { + border = "single", -- none, single, double, shadow + position = "bottom", -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] + winblend = 0, + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + align = "left", -- align columns left, center or right + }, + ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label + hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate + show_help = true, -- show help message on the command line when the popup is visible + show_keys = true, -- show the currently pressed key and its label as a message in the command line + triggers = "auto", -- automatically setup triggers + -- triggers = {""} -- or specify a list manually + triggers_blacklist = { + -- list of mode / prefixes that should never be hooked by WhichKey + -- this is mostly relevant for key maps that start with a native binding + -- most people should not need to change this + i = { "j", "k" }, + v = { "j", "k" }, + }, + -- disable the WhichKey popup for certain buf types and file types. + -- Disabled by deafult for Telescope + disable = { + buftypes = {}, + filetypes = { "TelescopePrompt" }, + }, + }, + + opts = { + mode = "n", -- NORMAL mode + prefix = "", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps + }, + vopts = { + mode = "v", -- VISUAL mode + prefix = "", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps + }, + -- NOTE: Prefer using : over as the latter avoids going back in normal-mode. + -- see https://neovim.io/doc/user/map.html#:map-cmd + vmappings = { + ["/"] = { "(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" }, + }, + mappings = { + [";"] = { "Alpha", "Dashboard" }, + ["w"] = { "w!", "Save" }, + ["q"] = { "confirm q", "Quit" }, + ["/"] = { "(comment_toggle_linewise_current)", "Comment toggle current line" }, + ["c"] = { "BufferKill", "Close Buffer" }, + ["f"] = { + function() + require("lvim.core.telescope.custom-finders").find_project_files { previewer = false } + end, + "Find File", + }, + ["h"] = { "nohlsearch", "No Highlight" }, + ["e"] = { "NvimTreeToggle", "Explorer" }, + b = { + name = "Buffers", + j = { "BufferLinePick", "Jump" }, + f = { "Telescope buffers previewer=false", "Find" }, + b = { "BufferLineCyclePrev", "Previous" }, + n = { "BufferLineCycleNext", "Next" }, + W = { "noautocmd w", "Save without formatting (noautocmd)" }, + -- w = { "BufferWipeout", "Wipeout" }, -- TODO: implement this for bufferline + e = { + "BufferLinePickClose", + "Pick which buffer to close", + }, + h = { "BufferLineCloseLeft", "Close all to the left" }, + l = { + "BufferLineCloseRight", + "Close all to the right", + }, + D = { + "BufferLineSortByDirectory", + "Sort by directory", + }, + L = { + "BufferLineSortByExtension", + "Sort by language", + }, + }, + d = { + name = "Debug", + t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, + b = { "lua require'dap'.step_back()", "Step Back" }, + c = { "lua require'dap'.continue()", "Continue" }, + C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, + d = { "lua require'dap'.disconnect()", "Disconnect" }, + g = { "lua require'dap'.session()", "Get Session" }, + i = { "lua require'dap'.step_into()", "Step Into" }, + o = { "lua require'dap'.step_over()", "Step Over" }, + u = { "lua require'dap'.step_out()", "Step Out" }, + p = { "lua require'dap'.pause()", "Pause" }, + r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, + s = { "lua require'dap'.continue()", "Start" }, + q = { "lua require'dap'.close()", "Quit" }, + U = { "lua require'dapui'.toggle({reset = true})", "Toggle UI" }, + }, + p = { + name = "Plugins", + i = { "Lazy install", "Install" }, + s = { "Lazy sync", "Sync" }, + S = { "Lazy clear", "Status" }, + c = { "Lazy clean", "Clean" }, + u = { "Lazy update", "Update" }, + p = { "Lazy profile", "Profile" }, + l = { "Lazy log", "Log" }, + d = { "Lazy debug", "Debug" }, + }, + + -- " Available Debug Adapters: + -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ + -- " Adapter configuration and installation instructions: + -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation + -- " Debug Adapter protocol: + -- " https://microsoft.github.io/debug-adapter-protocol/ + -- " Debugging + g = { + name = "Git", + g = { "lua require 'lvim.core.terminal'.lazygit_toggle()", "Lazygit" }, + j = { "lua require 'gitsigns'.next_hunk({navigation_message = false})", "Next Hunk" }, + k = { "lua require 'gitsigns'.prev_hunk({navigation_message = false})", "Prev Hunk" }, + l = { "lua require 'gitsigns'.blame_line()", "Blame" }, + p = { "lua require 'gitsigns'.preview_hunk()", "Preview Hunk" }, + r = { "lua require 'gitsigns'.reset_hunk()", "Reset Hunk" }, + R = { "lua require 'gitsigns'.reset_buffer()", "Reset Buffer" }, + s = { "lua require 'gitsigns'.stage_hunk()", "Stage Hunk" }, + u = { + "lua require 'gitsigns'.undo_stage_hunk()", + "Undo Stage Hunk", + }, + o = { "Telescope git_status", "Open changed file" }, + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope git_commits", "Checkout commit" }, + C = { + "Telescope git_bcommits", + "Checkout commit(for current file)", + }, + d = { + "Gitsigns diffthis HEAD", + "Git Diff", + }, + }, + l = { + name = "LSP", + a = { "lua vim.lsp.buf.code_action()", "Code Action" }, + d = { "Telescope diagnostics bufnr=0 theme=get_ivy", "Buffer Diagnostics" }, + w = { "Telescope diagnostics", "Diagnostics" }, + f = { "lua require('lvim.lsp.utils').format()", "Format" }, + i = { "LspInfo", "Info" }, + I = { "Mason", "Mason Info" }, + j = { + "lua vim.diagnostic.goto_next()", + "Next Diagnostic", + }, + k = { + "lua vim.diagnostic.goto_prev()", + "Prev Diagnostic", + }, + l = { "lua vim.lsp.codelens.run()", "CodeLens Action" }, + q = { "lua vim.diagnostic.setloclist()", "Quickfix" }, + r = { "lua vim.lsp.buf.rename()", "Rename" }, + s = { "Telescope lsp_document_symbols", "Document Symbols" }, + S = { + "Telescope lsp_dynamic_workspace_symbols", + "Workspace Symbols", + }, + e = { "Telescope quickfix", "Telescope Quickfix" }, + }, + L = { + name = "+LunarVim", + c = { + "edit " .. get_config_dir() .. "/config.lua", + "Edit config.lua", + }, + d = { "LvimDocs", "View LunarVim's docs" }, + f = { + "lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()", + "Find LunarVim files", + }, + g = { + "lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()", + "Grep LunarVim files", + }, + k = { "Telescope keymaps", "View LunarVim's keymappings" }, + i = { + "lua require('lvim.core.info').toggle_popup(vim.bo.filetype)", + "Toggle LunarVim Info", + }, + I = { + "lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()", + "View LunarVim's changelog", + }, + l = { + name = "+logs", + d = { + "lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())", + "view default log", + }, + D = { + "lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())", + "Open the default logfile", + }, + l = { + "lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())", + "view lsp log", + }, + L = { "lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())", "Open the LSP logfile" }, + n = { + "lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))", + "view neovim log", + }, + N = { "edit $NVIM_LOG_FILE", "Open the Neovim logfile" }, + }, + r = { "LvimReload", "Reload LunarVim's configuration" }, + u = { "LvimUpdate", "Update LunarVim" }, + }, + s = { + name = "Search", + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope colorscheme", "Colorscheme" }, + f = { "Telescope find_files", "Find File" }, + h = { "Telescope help_tags", "Find Help" }, + H = { "Telescope highlights", "Find highlight groups" }, + M = { "Telescope man_pages", "Man Pages" }, + r = { "Telescope oldfiles", "Open Recent File" }, + R = { "Telescope registers", "Registers" }, + t = { "Telescope live_grep", "Text" }, + k = { "Telescope keymaps", "Keymaps" }, + C = { "Telescope commands", "Commands" }, + l = { "Telescope resume", "Resume last search" }, + p = { + "lua require('telescope.builtin').colorscheme({enable_preview = true})", + "Colorscheme with Preview", + }, + }, + T = { + name = "Treesitter", + i = { ":TSConfigInfo", "Info" }, + }, + }, + } +end + +M.setup = function() + local which_key = require "which-key" + + which_key.setup(lvim.builtin.which_key.setup) + + local opts = lvim.builtin.which_key.opts + local vopts = lvim.builtin.which_key.vopts + + local mappings = lvim.builtin.which_key.mappings + local vmappings = lvim.builtin.which_key.vmappings + + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) + + return which_key +end + +return M -- cgit v1.2.3