From a48ba3f7dfe35c7ca622e63a72574134788d68c7 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 17 Jan 2023 00:08:43 +0100 Subject: Update key mappings --- fnl/plugins/core/lazy.fnl | 1 + fnl/plugins/editor/bufdel.fnl | 4 +- fnl/plugins/editor/colorizer.fnl | 5 +- fnl/plugins/editor/gitsigns.fnl | 27 +++++++ fnl/plugins/editor/harpoon.fnl | 4 ++ fnl/plugins/editor/persistence.fnl | 7 ++ fnl/plugins/editor/spectre.fnl | 7 +- fnl/plugins/editor/telescope.fnl | 59 ++++++++++++++- fnl/plugins/editor/toggleterm.fnl | 1 + fnl/plugins/editor/trouble.fnl | 5 +- fnl/plugins/editor/undotree.fnl | 4 +- fnl/plugins/editor/which-key.fnl | 144 +++---------------------------------- fnl/plugins/editor/zen.fnl | 1 + fnl/plugins/lsp/keymaps.fnl | 34 +++++++-- fnl/plugins/tools/diffview.fnl | 5 +- fnl/plugins/tools/neogit.fnl | 4 +- fnl/plugins/tools/orgmode.fnl | 9 ++- fnl/settings/keymaps.fnl | 55 +++++++------- 18 files changed, 196 insertions(+), 180 deletions(-) diff --git a/fnl/plugins/core/lazy.fnl b/fnl/plugins/core/lazy.fnl index f7b8371..69ad103 100644 --- a/fnl/plugins/core/lazy.fnl +++ b/fnl/plugins/core/lazy.fnl @@ -28,6 +28,7 @@ (fn setup [plugins] (let [lazy (require :lazy)] + (vim.keymap.set :n :y "Lazy home" {:desc :Home}) (lazy.setup plugins opts))) {: setup} diff --git a/fnl/plugins/editor/bufdel.fnl b/fnl/plugins/editor/bufdel.fnl index 4719a53..ad40db3 100644 --- a/fnl/plugins/editor/bufdel.fnl +++ b/fnl/plugins/editor/bufdel.fnl @@ -1,3 +1,5 @@ ;; Delete buffers. -{1 :ojroques/nvim-bufdel :cmd :BufDel} +{1 :ojroques/nvim-bufdel + :cmd :BufDel + :keys [{1 : 2 :BufDel :desc "Close Buffer"}]} diff --git a/fnl/plugins/editor/colorizer.fnl b/fnl/plugins/editor/colorizer.fnl index 553024b..67f05dd 100644 --- a/fnl/plugins/editor/colorizer.fnl +++ b/fnl/plugins/editor/colorizer.fnl @@ -1,3 +1,6 @@ ;; Display colors of hex numbers. -{1 :norcalli/nvim-colorizer.lua :cmd :ColorizerToggle :config true} +{1 :norcalli/nvim-colorizer.lua + :cmd :ColorizerToggle + :config true + :keys [{1 :h 2 :ColorizerToggle :desc :Colorizer}]} diff --git a/fnl/plugins/editor/gitsigns.fnl b/fnl/plugins/editor/gitsigns.fnl index 1ef8cbc..86f001c 100644 --- a/fnl/plugins/editor/gitsigns.fnl +++ b/fnl/plugins/editor/gitsigns.fnl @@ -1,5 +1,32 @@ ;; Add git signs to source files. +(local keys [{1 :mq 2 "Gitsigns diffthis HEAD" :desc "Gitsigns diff"} + {1 :gR + 2 "lua require 'gitsigns'.reset_buffer()" + :desc "Reset Buffer"} + {1 :gd 2 "Gitsigns diffthis HEAD" :desc :Diff} + {1 :gj + 2 "lua require 'gitsigns'.next_hunk()" + :desc "Next Hunk"} + {1 :gk + 2 "lua require 'gitsigns'.prev_hunk()" + :desc "Prev Hunk"} + {1 :gl + 2 "lua require 'gitsigns'.blame_line()" + :desc :Blame} + {1 :gp + 2 "lua require 'gitsigns'.preview_hunk()" + :desc "Preview Hunk"} + {1 :gr + 2 "lua require 'gitsigns'.reset_hunk()" + :desc "Reset Hunk"} + {1 :gs + 2 "lua require 'gitsigns'.stage_hunk()" + :desc "Stage Hunk"} + {1 :gu + 2 "lua require 'gitsigns'.undo_stage_hunk()" + :desc "Undo Stage Hunk"}]) + (local signs {:add {:hl :GitSignsAdd :text "|" :numhl :GitSignsAddNr diff --git a/fnl/plugins/editor/harpoon.fnl b/fnl/plugins/editor/harpoon.fnl index 7674f0b..876386e 100644 --- a/fnl/plugins/editor/harpoon.fnl +++ b/fnl/plugins/editor/harpoon.fnl @@ -21,5 +21,9 @@ {1 :ThePrimeagen/harpoon :event :BufReadPost + :keys [{1 :ma 2 :HarpoonAdd :desc :Harpoon} + {1 :mr 2 :HarpoonUI :desc "Harpoon UI"} + {1 :ms 2 :HarpoonPrev :desc "Harpoon Prev"} + {1 :mt 2 :HarpoonNext :desc "Harpoon Next"}] :config (fn [] (setup))} diff --git a/fnl/plugins/editor/persistence.fnl b/fnl/plugins/editor/persistence.fnl index 4cde73e..0b4e7a8 100644 --- a/fnl/plugins/editor/persistence.fnl +++ b/fnl/plugins/editor/persistence.fnl @@ -2,4 +2,11 @@ {1 :folke/persistence.nvim :event :VeryLazy + :keys [{1 :sn 2 :RestoreSession :desc "Restore session"} + {1 :se + 2 :RestoreLastSession + :desc "Restore last session"} + {1 :si + 2 :IgnoreSession + :desc "Ignore current session"}] :opts {:options [:buffers :curdir :tabpages :winsize :help]}} diff --git a/fnl/plugins/editor/spectre.fnl b/fnl/plugins/editor/spectre.fnl index 92a33ba..526b196 100644 --- a/fnl/plugins/editor/spectre.fnl +++ b/fnl/plugins/editor/spectre.fnl @@ -51,4 +51,9 @@ :is_open_target_win true :is_insert_mode false}) -{1 :windwp/nvim-spectre :event :BufReadPost : opts} +{1 :windwp/nvim-spectre + :event :BufReadPost + :keys [{1 :rn 2 :ReplaceInBuf :desc "Replace in Buffer"} + {1 :re 2 :Replace :desc :Replace} + {1 :ri 2 :ReplaceWord :desc "Replace Word"}] + : opts} diff --git a/fnl/plugins/editor/telescope.fnl b/fnl/plugins/editor/telescope.fnl index df8c031..163a322 100644 --- a/fnl/plugins/editor/telescope.fnl +++ b/fnl/plugins/editor/telescope.fnl @@ -1,5 +1,59 @@ ;; Telescope a highly extendable fuzzy finder over lists. +(local keys [{1 :mf 2 :FindFiles :desc "Find Files"} + {1 :mg + 2 "Telescope live_grep theme=dropdown" + :desc "Find Text"} + {1 :fc + 2 "Telescope commands theme=dropdown" + :desc :Commands} + {1 :fH + 2 "Telescope highlights" + :desc :Highlights} + {1 :fR + 2 "Telescope registers theme=dropdown" + :desc :Registers} + {1 :fS + 2 "Telescope grep_string theme=dropdown" + :desc "Find String"} + {1 :fb + 2 "Telescope git_branches theme=dropdown" + :desc "Checkout Branch"} + {1 :ff 2 :FindFiles :desc "Find files"} + {1 :fh + 2 "Telescope help_tags theme=dropdown" + :desc :Help} + {1 :fk + 2 "Telescope keymaps theme=dropdown" + :desc :Keymaps} + {1 :fl + 2 "Telescope resume theme=dropdown" + :desc "Last Search"} + {1 :fp + 2 "Telescope projects theme=dropdown" + :desc "Find Project"} + {1 :fr + 2 "Telescope oldfiles theme=dropdown" + :desc "Recent File"} + {1 :ft + 2 "Telescope live_grep theme=dropdown" + :desc "Find Text"} + {1 :js + 2 "Telescope diagnostics theme=dropdown" + :desc "Telescope Diagnostics"} + {1 :gb + 2 "Telescope git_branches theme=dropdown" + :desc "Checkout Branch"} + {1 :gc + 2 "Telescope git_commits theme=dropdown" + :desc "Checkout Commit"} + {1 :lS + 2 "Telescope lsp_dynamic_workspace_symbols" + :desc "Workspace Symbols"} + {1 :n + 2 "Telescope lsp_document_symbols theme=dropdown" + :desc "Document Symbols"}]) + (fn setup [] (let [telescope (require :telescope) actions (require :telescope.actions)] @@ -81,6 +135,8 @@ {1 :nvim-telescope/telescope.nvim :cmd :Telescope + :config (fn [] + (setup)) :dependencies [:nvim-lua/popup.nvim :nvim-telescope/telescope-frecency.nvim {1 :nvim-telescope/telescope-fzf-native.nvim :build :make} @@ -109,5 +165,4 @@ :nvim-telescope/telescope-fzf-native.nvim :nvim-telescope/telescope-frecency.nvim :joaomsa/telescope-orgmode.nvim] - :config (fn [] - (setup))} + : keys} diff --git a/fnl/plugins/editor/toggleterm.fnl b/fnl/plugins/editor/toggleterm.fnl index d75aea1..3086d40 100644 --- a/fnl/plugins/editor/toggleterm.fnl +++ b/fnl/plugins/editor/toggleterm.fnl @@ -2,4 +2,5 @@ {1 :akinsho/toggleterm.nvim :cmd :ToggleTerm + :keys [{1 :t 2 :ToggleTerm :desc :Terminal}] :opts {:size 16 :shade_terminals false}} diff --git a/fnl/plugins/editor/trouble.fnl b/fnl/plugins/editor/trouble.fnl index 3f736bb..9fb8f6d 100644 --- a/fnl/plugins/editor/trouble.fnl +++ b/fnl/plugins/editor/trouble.fnl @@ -78,4 +78,7 @@ ;; enabling this will use the signs defined in your lsp client }) -{1 :folke/trouble.nvim :cmd :TroubleToggle : opts} +{1 :folke/trouble.nvim + :cmd :TroubleToggle + :keys [{1 :jt 2 :TroubleToggle :desc :Trouble}] + : opts} diff --git a/fnl/plugins/editor/undotree.fnl b/fnl/plugins/editor/undotree.fnl index 9aa8114..05de139 100644 --- a/fnl/plugins/editor/undotree.fnl +++ b/fnl/plugins/editor/undotree.fnl @@ -1,3 +1,5 @@ ;; Tree of undo history. -{1 :mbbill/undotree :cmd :UndotreeToggle} +{1 :mbbill/undotree + :cmd :UndotreeToggle + :keys [{1 :u 2 :UndotreeToggle :desc :Undotree}]} diff --git a/fnl/plugins/editor/which-key.fnl b/fnl/plugins/editor/which-key.fnl index 0b6389c..9ea8ff8 100644 --- a/fnl/plugins/editor/which-key.fnl +++ b/fnl/plugins/editor/which-key.fnl @@ -10,157 +10,31 @@ :nav true :z true :g true}} - :icons {:breadcrumb "»" :separator "" :group "+"} + :icons {:breadcrumb "»" :separator " " :group "+"} :popup_mappings {:scroll_down : :scroll_up :} :window {:border :rounded :position :bottom :winblend 0} :layout {:height {:min 4 :max 25} :width {:min 20 :max 50} :spacing 3 :align :left} - :ignore_missing true :hidden [: : : : :call :lua "^:" "^ "] :show_help true :triggers :auto :disable {:filetypes [:netrw]} :triggers_blacklist {:i [:j :k] :v [:j :k]}}) -(local mopts {:mode :n - :prefix :m - :buffer nil - :silent true - :noremap true - :nowait true}) - -(local mmappings {:a [:HarpoonAdd :Harpoon] - :d [:DiffviewFileHistory :DiffviewFileHistory] - :f [:FindFiles "Find files"] - :g ["Telescope live_grep theme=dropdown" - "Find text"] - :n [:Neogit :Neogit] - :q ["Gitsigns diffthis HEAD" "Gitsigns diff"] - :r [:HarpoonUI "Harpoon UI"] - :s [:HarpoonPrev "Harpoon Prev"] - :t [:HarpoonNext "Harpoon Next"] - :v ["lua vim.lsp.buf.rename()" :Rename] - :x ["DiffviewOpen -uno" :DiffviewOpen] - :z [:DiffviewClose :DiffviewClose]}) - -(local nopts {:mode :n - :prefix : - :buffer nil - :silent true - :noremap true - :nowait true}) - -(local find - {:name :find - :C ["Telescope commands theme=dropdown" :Commands] - :H ["Telescope highlights" :Highlights] - :R ["Telescope registers theme=dropdown" :Registers] - :S ["Telescope grep_string theme=dropdown" "Find String"] - :b ["Telescope git_branches theme=dropdown" "Checkout branch"] - :c ["Telescope colorscheme theme=dropdown" :Colorscheme] - :f [:FindFiles "Find files"] - :h ["Telescope help_tags theme=dropdown" :Help] - :k ["Telescope keymaps theme=dropdown" :Keymaps] - :l ["Telescope resume theme=dropdown" "Last Search"] - :p ["Telescope projects theme=dropdown" "Find project"] - :r ["Telescope oldfiles theme=dropdown" "Recent File"] - :t ["Telescope live_grep theme=dropdown" "Find text"]}) - -(local diagnostics {:name :diagnostics - :t [:TroubleToggle :Trouble] - :g ["Telescope diagnostics theme=dropdown" - "Telescope diagnostics"]}) - -(local git {:name :git - :R ["lua require 'gitsigns'.reset_buffer()" - "Reset Buffer"] - :b ["Telescope git_branches theme=dropdown" - "Checkout branch"] - :c ["Telescope git_commits theme=dropdown" - "Checkout commit"] - :d ["Gitsigns diffthis HEAD" :Diff] - :j ["lua require 'gitsigns'.next_hunk()" "Next Hunk"] - :k ["lua require 'gitsigns'.prev_hunk()" "Prev Hunk"] - :l ["lua require 'gitsigns'.blame_line()" :Blame] - :o ["Telescope git_status theme=dropdown" - "Open changed file"] - :p ["lua require 'gitsigns'.preview_hunk()" - "Preview Hunk"] - :r ["lua require 'gitsigns'.reset_hunk()" "Reset Hunk"] - :s ["lua require 'gitsigns'.stage_hunk()" "Stage Hunk"] - :u ["lua require 'gitsigns'.undo_stage_hunk()" - "Undo Stage Hunk"]}) - -(local lsp - {:name :lsp - :S ["Telescope lsp_dynamic_workspace_symbols" - "Workspace Symbols"] - :a ["lua vim.lsp.buf.code_action()" "Code Action"] - :f ["lua vim.lsp.buf.format { async = true }" :Format] - :i [:LspInfo :Info] - :l ["lua vim.lsp.codelens.run()" "CodeLens Action"] - :r ["lua vim.lsp.buf.rename()" :Rename] - :s ["Telescope lsp_document_symbols" "Document Symbols"]}) - -(local replace {:name :replace - :m [:ReplaceInBuf "Replace in Buffer"] - :n [:Replace :Replace] - :e [:ReplaceWord "Replace Word"]}) - -(local session - {:name :session - :m [:RestoreSession "Restore session"] - :n [:RestoreLastSession "Restore last session"] - :e [:IgnoreSession "Ignore current session"]}) - -(local treesitter - {:name :Treesitter :p [:TSPlaygroundToggle :Playground]}) - -(local nmappings {:a ["Telescope lsp_document_symbols theme=dropdown" - "Document Symbols"] - :T treesitter - : [:BufDel "Close Buffer"] - :j diagnostics - :f find - :g git - :h [:ColorizerToggle :Colorizer] - :l lsp - :m [:Mason :Mason] - :n [:SymbolsOutline "Symbols outline"] - :r replace - :s session - :t [:ToggleTerm :Terminal] - :u [:UndotreeToggle :Undotree] - :y ["Lazy home" :Home] - :z [:ZenMode "Zen Mode"]}) - -(local vopts {:mode :v - :prefix : - :buffer nil - :silent true - :noremap true - :nowait true}) - -(local gopts {:mode :n - :prefix :g - :buffer nil - :silent true - :noremap true - :nowait true}) - -(local gmappings {:a [:OrgAgendaPrompt "Open agenda prompt"] - :c [:OrgCapturePrompt "Open capture prompt"] - :m ["Telescope orgmode search_headings theme=dropdown" - "Search headings"]}) +(local groups {:mode [:n :v] + :g {:name :+git} + :j {:name :+diagnostics} + :f {:name :+find} + :l {:name :+lsp} + :r {:name :+replace} + :s {:name :+session}}) (fn setup [] (let [which-key (require :which-key)] (which-key.setup opts) - (which-key.register mmappings mopts) - (which-key.register nmappings nopts) - (which-key.register gmappings gopts))) + (which-key.register groups))) {1 :folke/which-key.nvim :event :VeryLazy diff --git a/fnl/plugins/editor/zen.fnl b/fnl/plugins/editor/zen.fnl index 6e9bee7..11685af 100644 --- a/fnl/plugins/editor/zen.fnl +++ b/fnl/plugins/editor/zen.fnl @@ -2,6 +2,7 @@ {1 :folke/zen-mode.nvim :cmd :ZenMode + :keys [{1 :z 2 :ZenMode :desc "Zen Mode"}] :opts {:window {:backdrop 1 :height 1 :width 120 diff --git a/fnl/plugins/lsp/keymaps.fnl b/fnl/plugins/lsp/keymaps.fnl index cd62073..fdcf53f 100644 --- a/fnl/plugins/lsp/keymaps.fnl +++ b/fnl/plugins/lsp/keymaps.fnl @@ -3,16 +3,36 @@ (local opts {:noremap true :silent true}) (local mappings - [[:n :gD "lua vim.lsp.buf.declaration()"] - [:n :gd "lua vim.lsp.buf.definition()"] - [:n :gI "lua vim.lsp.buf.implementation()"] - [:n :gr "lua vim.lsp.buf.references()"] - [:n :gl "lua vim.diagnostic.open_float()"] - [:n :gs "lua vim.lsp.buf.signature_help()"]]) + [[:n :gD "lua vim.lsp.buf.declaration()" {:desc :Declaration}] + [:n :gd "lua vim.lsp.buf.definition()" {:desc :Definition}] + [:n + :gI + "lua vim.lsp.buf.implementation()" + {:desc :Implementation}] + [:n :gr "lua vim.lsp.buf.references()" {:desc :References}] + [:n + :gl + "lua vim.diagnostic.open_float()" + {:desc :Diagnostics}] + [:n :gs "lua vim.lsp.buf.signature_help()" {:desc :Signature}] + [:n :gv "lua vim.lsp.buf.rename()" {:desc :Rename}] + [:n + :a + "lua vim.lsp.buf.code_action()" + {:desc "Code Action"}] + [:n + :e + "lua vim.lsp.buf.format { async = true }" + {:desc :Format}] + [:n + :i + "lua vim.lsp.codelens.run()" + {:desc "Code Lens"}] + [:n :li :LspInfo {:desc "Lsp Info"}]]) (fn on-attach [bufnr] (each [_ mapping (ipairs mappings)] (match mapping - [mode key cmd] (vim.api.nvim_buf_set_keymap bufnr mode key cmd opts)))) + [mode key cmd desc] (vim.api.nvim_buf_set_keymap bufnr mode key cmd (vim.tbl_extend :force opts desc))))) {: on-attach} diff --git a/fnl/plugins/tools/diffview.fnl b/fnl/plugins/tools/diffview.fnl index 9978c2e..c004199 100644 --- a/fnl/plugins/tools/diffview.fnl +++ b/fnl/plugins/tools/diffview.fnl @@ -2,4 +2,7 @@ {1 :sindrets/diffview.nvim :cmd [:DiffviewFileHistory :DiffviewOpen] - :config true} + :config true + :keys [{1 :md 2 :DiffviewFileHistory :desc :DiffviewFileHistory} + {1 :mx 2 "DiffviewOpen -uno" :desc :DiffviewOpen} + {1 :mz 2 :DiffviewClose :desc :DiffviewClose}]} diff --git a/fnl/plugins/tools/neogit.fnl b/fnl/plugins/tools/neogit.fnl index b7c1633..9bd3afd 100644 --- a/fnl/plugins/tools/neogit.fnl +++ b/fnl/plugins/tools/neogit.fnl @@ -2,5 +2,7 @@ {1 :TimUntersberger/neogit :cmd :Neogit + :config true :dependencies [:nvim-lua/plenary.nvim] - :config true} + :keys [{1 :mn 2 :Neogit :desc :Neogit}] +} diff --git a/fnl/plugins/tools/orgmode.fnl b/fnl/plugins/tools/orgmode.fnl index 99e55be..be96fd7 100644 --- a/fnl/plugins/tools/orgmode.fnl +++ b/fnl/plugins/tools/orgmode.fnl @@ -19,6 +19,11 @@ (orgmode.setup opts))) {1 :nvim-orgmode/orgmode - :event :BufReadPost :config (fn [] - (setup))} + (setup)) + :event :BufReadPost + :keys [{1 :ga 2 :OrgAgendaPrompt :desc "Open agenda prompt"} + {1 :gc 2 :OrgCapturePrompt :desc "Open capture prompt"} + {1 :gm + 2 "Telescope orgmode search_headings theme=dropdown" + :desc "Search headings"}]} diff --git a/fnl/settings/keymaps.fnl b/fnl/settings/keymaps.fnl index 04073c8..7c323ea 100644 --- a/fnl/settings/keymaps.fnl +++ b/fnl/settings/keymaps.fnl @@ -3,46 +3,47 @@ (local opts {:noremap true :silent true}) (local mappings [;;Remap space as leader key - ["" : :] + ["" : : {}] ;; Normal ;; ;; Better window navigation - [:n : :h] - [:n : :j] - [:n : :k] - [:n : :l] + [:n : :h {}] + [:n : :j {}] + [:n : :k {}] + [:n : :l {}] ;; Resize with arrows - [:n : ":resize -2"] - [:n : ":resize +2"] - [:n : ":vertical resize -2"] - [:n : ":vertical resize +2"] + [:n : ":resize -2" {}] + [:n : ":resize +2" {}] + [:n : ":vertical resize -2" {}] + [:n : ":vertical resize +2" {}] ;; Visual ;; ;; Stay in indent mode - [:v "<" :" :>gv] + [:v "<" :" :>gv {}] ;; Visual Block ;; ;; Move text up and down - [:x :J ":move '>+1gv-gv"] - [:x :K ":move '<-2gv-gv"] + [:x :J ":move '>+1gv-gv" {}] + [:x :K ":move '<-2gv-gv" {}] ;; Move text up and down - [:v : ":m .+1=="] - [:v : ":m .-2=="] - [:v :p "\"_dP"] + [:v : ":m .+1==" {}] + [:v : ":m .-2==" {}] + [:v :p "\"_dP" {}] ;; Splits - [:n : :split] - [:n : :vsplit] + [:n : :split {}] + [:n : :vsplit {}] ;; Buf navigation - [:n : :bprev] - [:n : :bnext] - ;; Jump half a page and centralize the view - [:n : :zz] - [:n : :zz] + [:n : :bprev {}] + [:n : :bnext {}] + ;; Jump half a page and centralize the view + [:n : :zz {}] + [:n : :zz {}] ;; Remove highlighted search - [:n : :nohlsearch] + [:n : :nohlsearch {}] ;; Close window - [:n :Q ":q"] + [:n :Q ":q" {}] ;; Force refresh - [:n :mj ":e"]]) + [:n :mj ":e" {:desc :Refresh}]]) (each [_ mapping (ipairs mappings)] (match mapping - [mode key cmd] (vim.api.nvim_set_keymap mode key cmd opts))) + [mode key cmd desc] + (vim.api.nvim_set_keymap mode key cmd (vim.tbl_extend :force opts desc)))) -- cgit v1.2.3-70-g09d2