(let [mod {} keymap vim.keymap (ok-substitute substitute) (pcall require :substitute) (ok-fzf fzf) (pcall require :fzf-lua) fzf-layout-bottom {:winopts_fn #(let [height (math.floor (* vim.o.lines 0.4))] {:split (.. "belowright new | resize " (tostring height))})} fzf-layout-dropdown {:winopts {:height 0.4 :width 0.6 :preview {:hidden :hidden}}} (ok-npairs npairs) (pcall require :nvim-autopairs) (ok-hover hover) (pcall require :hover) (ok-gitsigns gitsigns) (pcall require :gitsigns) (ok-neogit neogit) (pcall require :neogit) (ok-wk wk) (pcall require :which-key) repl (require :nifoc.repl) repo (require :nifoc.repo) formatting (require :nifoc.formatting)] (fn mod.setup [] (keymap.set :n : : {:noremap true}) ;; Leader Mappings (when ok-fzf (keymap.set :n :o fzf.files {:desc "Find Files"}) (keymap.set :n :s #(fzf.live_grep fzf-layout-bottom) {:desc "Live Grep"})) (keymap.set :n :fn :enew {:desc "New File"}) (keymap.set :n :u "UrlView buffer" {:desc "Open UrlView"}) (keymap.set :n :c repl.open-shell {:desc "Open Shell"}) (keymap.set :n :r repl.open-repl {:desc "Open REPL"}) (when ok-fzf (keymap.set :n :bl fzf.buffers {:desc "List Buffers"}) (keymap.set :n :bf fzf.grep_curbuf {:desc "Find In Buffer"}) (keymap.set :n :bt fzf.treesitter {:desc "Find via Treesitter"})) (when ok-neogit (keymap.set :n :g #(neogit.open {:kind :split}) {:desc "Open Neogit"}) (keymap.set :n :vs #(neogit.open {:kind :split}) {:desc "VCS Status"})) (when ok-fzf (keymap.set :n :vb #(fzf.git_branches fzf-layout-dropdown) {:desc "List VCS Branches"})) (when ok-gitsigns (keymap.set :n :vl #(gitsigns.blame_line {:full true}) {:desc "Blame Line"})) (keymap.set :n :vd :DiffviewOpen {:desc "Open DiffView"}) (keymap.set :n :vvr #(repo.open-repo) {:desc "Open repository"}) (keymap.set :n :vvm #(repo.open-merge-request) {:desc "Open MR"}) (keymap.set :n :vvc #(repo.open-ci) {:desc "Open CI"}) (keymap.set :n :vtc #(repo.run-ci) {:desc "Trigger CI"}) (when ok-fzf (keymap.set :n :lk fzf.keymaps {:desc "Show Keymappings"}) (keymap.set :n :ld #(fzf.diagnostics_document fzf-layout-bottom) {:desc "Show Diagnostics"}) (keymap.set :n :lt :TodoFzfLua {:desc "Show Todo Comments"})) (keymap.set :n :dli :LspInfo {:desc "LSP Info"}) (keymap.set :n :dlr :LspRestart {:desc "Restart LSP"}) (keymap.set :n :ds #(vim.diagnostic.open_float {:scope :line}) {:desc "Show Line Diagnostics"}) (keymap.set :n :dtp :TSPlaygroundToggle {:desc "Toggle Treetsitter Playground"}) ;; Other Mappings (when ok-npairs (keymap.set :i : npairs.autopairs_cr {:expr true :replace_keycodes false :silent true})) (keymap.set :n :F #(formatting.maybe-format-buffer 0) {:desc "Format Buffer"}) (keymap.set :n : :b) (keymap.set :n : :w) (keymap.set :n : "^") (keymap.set :n : "$") (keymap.set :i : :b) (keymap.set :i : :w) (keymap.set :i : :^) (keymap.set :i : :$) (keymap.set :n : "MoveLine -1" {:noremap true :silent true}) (keymap.set :n : "MoveLine 1" {:noremap true :silent true}) (keymap.set :x : "MoveBlock -1" {:noremap true :silent true}) (keymap.set :x : "MoveBlock 1" {:noremap true :silent true}) (keymap.set :n :p "(YankyPutAfter)") (keymap.set :n :P "(YankyPutBefore)") (when ok-substitute (keymap.set :x :p substitute.visual)) (keymap.set :x :P "(YankyPutBefore)") (keymap.set :n :gp "(YankyGPutAfter)") (keymap.set :n :gP "(YankyGPutBefore)") (keymap.set :x :gp "(YankyGPutAfter)") (keymap.set :x :gP "(YankyGPutBefore)") (keymap.set :n :y "(YankyYank)") (keymap.set :x :y "(YankyYank)") (keymap.set :n "-" :Oil {:desc "Open Oil"}) ;; hover.nvim (when ok-hover (keymap.set :n :K hover.hover {:desc "Show Documentation"}) (keymap.set :n :gK hover.hover_select {:desc "hover.nvim selection"}) (keymap.set :n : #(hover.hover_switch :previous) {:desc "hover.nvim previous source"}) (keymap.set :n : #(hover.hover_switch :next) {:desc "hover.nvim next source"})) ;; Label (when ok-wk (wk.add [{1 :v :group :vcs} {1 :l :group :list/lsp} {1 :d :group :debug}]))) (fn mod.lsp-attach [_client bufnr] (when ok-fzf (keymap.set :n :t #(fzf.lsp_document_symbols fzf-layout-dropdown) {:buffer bufnr :desc "LSP Document Symbols"}) (keymap.set :n :tw #(fzf.lsp_workspace_symbols fzf-layout-dropdown) {:buffer bufnr :desc "LSP Workspace Symbols"})) (keymap.set :n :th #(vim.lsp.inlay_hint.enable (not (vim.lsp.inlay_hint.is_enabled bufnr)) {: bufnr}) {:buffer bufnr :desc "Toggle Inlay Hints"}) (when ok-fzf (keymap.set :n :lca fzf.lsp_code_actions {:buffer bufnr :desc "LSP Code Action"}) (keymap.set :n :lfr fzf.lsp_references {:buffer bufnr :desc "Find References"}) (keymap.set :n :lfd fzf.lsp_definitions {:buffer bufnr :desc "Find Definitions"}) (keymap.set :n :lfi fzf.lsp_implementations {:buffer bufnr :desc "Find Implementations"}))) (fn mod.terminal-open [bufnr] (let [map-opts {:buffer bufnr}] (keymap.set :t : "" map-opts) (keymap.set :t : "h" map-opts) (keymap.set :t : "j" map-opts) (keymap.set :t : "k" map-opts) (keymap.set :t : "l" map-opts))) mod)