(import-macros {: nmap : map : vmap : imap : tmap : normal!} :macros) ;; buffer switching ; (nmap : ":bnext zz" {:noremap true}) ; (nmap : ":bprev zz" {:noremap true}) (nmap :bn vim.cmd.bnext {:desc :bnext}) (nmap :bp vim.cmd.bprev {:desc :bprev}) (nmap :bd #(vim.api.nvim_buf_delete 0 {}) {:desc :bdelete}) ;; move up/down visual lines (nmap :k "v:count == 0 ? 'gk' : 'k'" {:expr true :silent true}) (nmap :j "v:count == 0 ? 'gj' : 'j'" {:expr true :silent true}) ;; center cursor on navigation (each [_ key (ipairs [: : "{" "}" "(" ")" "*" "#" :g* "g#" :G])] (nmap key (.. key :zz))) (nmap :n :nzzzv) (nmap :N :Nzzzv) ;; move visual selections (vmap :J ":m '>+1gv=gv") (vmap :K ":m '<-2gv=gv") ;; Better indents (vmap ">" :>gv) (vmap "<" : (nmap : :noh {:silent true}) ;; exit terminal insert with (tmap : "" {:nowait true}) ;; unbind s (nmap :s : {:silent true}) ;; commenting (each [mode cmd (pairs {:x "normal gc" :n "normal gcc"})] (map mode :/ #(let [pos (vim.api.nvim_win_get_cursor 0)] (vim.cmd cmd) (vim.api.nvim_win_set_cursor 0 pos)) {:desc "Toggle Comment" :remap true})) ;; Netrw (nmap : #(if (= vim.bo.filetype :netrw) (vim.cmd :bd) (vim.cmd :Explore))) ;; diagnostic jumps (each [key cmd (pairs {"]d" vim.diagnostic.get_next "[d" vim.diagnostic.get_prev})] (nmap key #(let [d (cmd {:severity {:min vim.diagnostic.severity.WARN}})] (if d (vim.diagnostic.jump {:diagnostic d}) (normal! :zz))))) ;; open diagnostics ;; TODO: applying this only when an LSP attaches would also save some time (nmap :m vim.diagnostic.open_float {:desc "open floating diagnostic"}) (nmap :q vim.diagnostic.setloclist {:desc "open diagnostics list"}) ;; lsp ;; TODO: maybe only set these keymaps once an LSP attaches? (vim.lsp is a heavier part of the config) ;; - pendulum being a language server may make this pointless though (nmap :rn vim.lsp.buf.rename {:desc :rename}) (nmap :k vim.lsp.buf.signature_help {:desc "signature help"}) (imap : vim.lsp.buf.signature_help) (nmap :gD vim.lsp.buf.declaration {:desc "goto declaration"}) (nmap :wa vim.lsp.buf.add_workspace_folder {:desc "workspace add dir"}) (nmap :wr vim.lsp.buf.remove_workspace_folder {:desc "workspace remove dir"}) (nmap :wl vim.lsp.buf.list_workspace_folders {:desc "workspace list dirs"}) (nmap :gt (fn [] (vim.lsp.buf.type_definition) (normal! :zz)) {:desc "goto type definition"}) ;; paste/delete w/o yank (vmap :d #(normal! :_d) {:desc :_d}) (vmap :p #(normal! :_dP) {:desc :_dP}) ;; make file executable (nmap :x+ "silent !chmod +x %" {:desc "chmod +x"}) (nmap :x- "silent !chmod -x %" {:desc "chmod -x"}) ;; tmux-sessionizer (nmap : "sil !tmux neww ~/dotfiles/scripts/tmux-sessionizer.sh") ;; treesitter inspect (nmap :zS vim.show_pos {:desc :inspect}) ;; alternate file (nmap : :zz) ;; navigate to next/prev TODO comments (let [todo-pattern "\\v\\s*(TODO|FIX|HACK|NOTE|DOCS|REFACTOR|CHANGE|REVIEW|FIX|TEST|DEBUG):\\s*"] (nmap "]t" (fn [] (vim.fn.search todo-pattern) (normal! :zz)) {:desc "next todo comment"}) (nmap "[t" (fn [] (vim.fn.search todo-pattern :b) (normal! :zz)) {:desc "prev todo comment"})) ;; yank file path (nmap :yf (fn [] (vim.fn.setreg "+" (vim.fn.expand "%")) (vim.notify (.. "Yanked: " (vim.fn.expand "%")))) {:desc "yank path"}) (nmap :ut :Undotree {:desc :undotree})