From 540268d618627079c9b958a955b586e1888b46a8 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 10 Aug 2021 23:15:04 +0200 Subject: Major refactor of nvim --- .config/nvim/lua/core/which-key.lua | 79 +++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 26 deletions(-) (limited to '.config/nvim/lua/core/which-key.lua') diff --git a/.config/nvim/lua/core/which-key.lua b/.config/nvim/lua/core/which-key.lua index dabf832..6227a8e 100644 --- a/.config/nvim/lua/core/which-key.lua +++ b/.config/nvim/lua/core/which-key.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.which_key = { + options.builtin.which_key = { active = false, setup = { plugins = { @@ -58,7 +59,7 @@ M.config = function() -- NOTE: Prefer using : over as the latter avoids going back in normal-mode. -- see https://neovim.io/doc/user/map.html#:map-cmd vmappings = { - ["/"] = { ":CommentToggle", "Comment" }, + ["k"] = { ":CommentToggle", "Comment" }, }, mappings = { ["w"] = { "w!", "Save" }, @@ -68,14 +69,36 @@ M.config = function() ["e"] = { "lua require'core.nvimtree'.toggle_tree()", "Explorer" }, ["f"] = { "Telescope find_files", "Find File" }, ["n"] = { 'let @/=""', "No Highlight" }, - ["h"] = { "vsplit", "Vertical Split" }, - ["v"] = { 'split', "Horizontal Split" }, + b = { + name = "Buffers", + j = { "BufferPick", "jump to buffer" }, + f = { "Telescope buffers", "Find buffer" }, + w = { "BufferWipeout", "wipeout buffer" }, + e = { + "BufferCloseAllButCurrent", + "close all but current buffer", + }, + h = { "BufferCloseBuffersLeft", "close all buffers to the left" }, + l = { + "BufferCloseBuffersRight", + "close all BufferLines to the right", + }, + D = { + "BufferOrderByDirectory", + "sort BufferLines automatically by directory", + }, + L = { + "BufferOrderByLanguage", + "sort BufferLines automatically by language", + }, + }, p = { name = "Packer", c = { "PackerCompile", "Compile" }, i = { "PackerInstall", "Install" }, - r = { "lua require('utils').reload_config()", "Reload" }, + r = { "lua require('utils').reload_lv_config()", "Reload" }, s = { "PackerSync", "Sync" }, + S = { "PackerStatus", "Status" }, u = { "PackerUpdate", "Update" }, }, @@ -119,18 +142,24 @@ M.config = function() "Telescope lsp_workspace_diagnostics", "Workspace Diagnostics", }, - f = { "silent FormatWrite", "Format" }, + -- f = { "silent FormatWrite", "Format" }, + f = { "lua vim.lsp.buf.formatting()", "Format" }, i = { "LspInfo", "Info" }, j = { - "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})", + "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = options.lsp.popup_border}})", "Next Diagnostic", }, k = { - "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})", + "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = options.lsp.popup_border}})", "Prev Diagnostic", }, - l = { "silent lua require('lint').try_lint()", "Lint" }, - q = { "Telescope quickfix", "Quickfix" }, + p = { + name = "Peek", + d = { "lua require('lsp.peek').Peek('definition')", "Definition" }, + t = { "lua require('lsp.peek').Peek('typeDefinition')", "Type Definition" }, + i = { "lua require('lsp.peek').Peek('implementation')", "Implementation" }, + }, + q = { "lua vim.lsp.diagnostic.set_loclist()", "Quickfix" }, r = { "lua vim.lsp.buf.rename()", "Rename" }, s = { "Telescope lsp_document_symbols", "Document Symbols" }, S = { @@ -138,6 +167,14 @@ M.config = function() "Workspace Symbols", }, }, + I = { + name = "+nvim", + k = { "lua require('keymappings').print()", "View nvim's default keymappings" }, + i = { + "lua require('core.info').toggle_popup(vim.bo.filetype)", + "Toggle nvim Info", + }, + }, s = { name = "Search", @@ -170,32 +207,22 @@ M.setup = function() -- end local status_ok, which_key = pcall(require, "which-key") if not status_ok then + Log:get_default "Failed to load whichkey" return end - which_key.setup(O.plugin.which_key.setup) - - local opts = O.plugin.which_key.opts - local vopts = O.plugin.which_key.vopts + which_key.setup(options.builtin.which_key.setup) - local mappings = O.plugin.which_key.mappings - local vmappings = O.plugin.which_key.vmappings + local opts = options.builtin.which_key.opts + local vopts = options.builtin.which_key.vopts - -- if O.plugin.ts_playground.active then - -- vim.api.nvim_set_keymap("n", "Th", ":TSHighlightCapturesUnderCursor", { noremap = true, silent = true }) - -- mappings[""] = "Highlight Capture" - -- end - - if O.plugin.zen.active then - vim.api.nvim_set_keymap("n", "z", ":ZenMode", { noremap = true, silent = true }) - mappings["z"] = "Zen" - end + local mappings = options.builtin.which_key.mappings + local vmappings = options.builtin.which_key.vmappings local wk = require "which-key" wk.register(mappings, opts) wk.register(vmappings, vopts) - wk.register(O.user_which_key, opts) end return M -- cgit v1.2.3-70-g09d2