From 918a26ebc070ba21e5073b85a0addac867057617 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 26 Jun 2021 19:20:07 +0200 Subject: Fix spectre (#520) * Correctly require Spectre plugin. Configure backslash as key for interacting with spectre's results. * Refactor + add Spectre mapping Map all keys using the mapping variables. Explicitly specify virtual mappings. * Remove already prepended character from mapping keys Co-authored-by: Christian Chiarulli --- lua/lv-which-key/init.lua | 65 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'lua/lv-which-key/init.lua') diff --git a/lua/lv-which-key/init.lua b/lua/lv-which-key/init.lua index 3713a262..27f1b406 100644 --- a/lua/lv-which-key/init.lua +++ b/lua/lv-which-key/init.lua @@ -47,6 +47,7 @@ local opts = { vim.api.nvim_set_keymap('n', '', '', {noremap = true, silent = true}) vim.g.mapleader = ' ' + -- no hl vim.api.nvim_set_keymap('n', 'h', ':let @/=""', {noremap = true, silent = true}) @@ -69,26 +70,28 @@ vim.api.nvim_set_keymap("n", "c", ":BufferClose", {noremap = true, s -- open projects vim.api.nvim_set_keymap('n', 'p', ":lua require'telescope'.extensions.project.project{}", {noremap = true, silent = true}) + -- TODO create entire treesitter section local mappings = { - ["/"] = "Comment", - ["c"] = "Close Buffer", - ["e"] = "Explorer", - ["f"] = "Find File", - ["h"] = "No Highlight", - ["p"] = "Projects", + ["/"] = {"CommentToggle", "Comment"}, + [";"] = {"Dashboard", "Dashboard"}, + ["c"] = {"BufferClose", "Close Buffer"}, + ["e"] = {"NvimTreeToggle", "Explorer"}, + ["f"] = {"Telescope find_files", "Find File"}, + ["h"] = {"set hlsearch!", "No Highlight"}, + ["p"] = {"lua require'telescope'.extensions.project.project{}", "Projects"}, d = { - name = "+Diagnostics", + name = "Diagnostics", t = {"TroubleToggle", "trouble"}, w = {"TroubleToggle lsp_workspace_diagnostics", "workspace"}, d = {"TroubleToggle lsp_document_diagnostics", "document"}, q = {"TroubleToggle quickfix", "quickfix"}, l = {"TroubleToggle loclist", "loclist"}, - r = {"TroubleToggle lsp_references", "references"}, + r = {"TroubleToggle lsp_references", "references"} }, D = { - name = "+Debug", + name = "Debug", b = {"DebugToggleBreakpoint", "Toggle Breakpoint"}, c = {"DebugContinue", "Continue"}, i = {"DebugStepInto", "Step Into"}, @@ -97,7 +100,7 @@ local mappings = { s = {"DebugStart", "Start"} }, g = { - name = "+Git", + name = "Git", j = {"NextHunk", "Next Hunk"}, k = {"PrevHunk", "Prev Hunk"}, p = {"PreviewHunk", "Preview Hunk"}, @@ -108,10 +111,10 @@ local mappings = { 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)"}, + C = {"Telescope git_bcommits", "Checkout commit(for current file)"} }, l = { - name = "+LSP", + name = "LSP", a = {"Lspsaga code_action", "Code Action"}, A = {"Lspsaga range_code_action", "Selected Action"}, d = {"Telescope lsp_document_diagnostics", "Document Diagnostics"}, @@ -128,8 +131,13 @@ local mappings = { s = {"Telescope lsp_document_symbols", "Document Symbols"}, S = {"Telescope lsp_dynamic_workspace_symbols", "Workspace Symbols"} }, + r = { + name = "Replace", + f = {"lua require('spectre').open_file_search()", "Current File"}, + p = {"lua require('spectre').open()", "Project"} + }, s = { - name = "+Search", + name = "Search", b = {"Telescope git_branches", "Checkout branch"}, c = {"Telescope colorscheme", "Colorscheme"}, d = {"Telescope lsp_document_diagnostics", "Document Diagnostics"}, @@ -141,16 +149,39 @@ local mappings = { R = {"Telescope registers", "Registers"}, t = {"Telescope live_grep", "Text"} }, - S = {name = "+Session", s = {"SessionSave", "Save Session"}, l = {"SessionLoad", "Load Session"}}, - + S = { + name = "Session", + s = {"SessionSave", "Save Session"}, + l = {"SessionLoad", "Load Session"} + }, -- extras z = { - name = "+Zen", + name = "Zen", s = {"TZBottom", "toggle status line"}, t = {"TZTop", "toggle tab bar"}, - z = {"TZAtaraxis", "toggle zen"}, + z = {"TZAtaraxis", "toggle zen"} + } +} + +local visualOpts = { + 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 = false -- use `nowait` when creating keymaps +} + +local visualMappings = { + ["/"] = {"CommentToggle", "Comment"}, + r = { + name = "Replace", + f = {"lua require('spectre').open_visual({path = vim.fn.expand('%')})", "File"}, + p = {"lua require('spectre').open_visual()", "Project"} } } local wk = require("which-key") wk.register(mappings, opts) +wk.register(visualMappings, visualOpts) + -- cgit v1.2.3