1
0
Fork 0
dotfiles/config/nvim/nifoc/keymap.fnl

160 lines
9.3 KiB
Text
Raw Normal View History

2022-04-05 19:57:44 +00:00
(let [mod {}
keymap vim.keymap
legendary (require :legendary)
substitute (require :substitute)
2022-04-05 19:57:44 +00:00
telescope (require :telescope)
telescope-builtin (require :telescope.builtin)
telescope-themes (require :telescope.themes)
telescope-nifoc (require :nifoc.telescope)
2022-04-21 16:55:53 +00:00
telescope-toggleterm (require :telescope-toggleterm)
2022-04-05 19:57:44 +00:00
telescope-ivy (telescope-themes.get_ivy)
telescope-dropdown (telescope-themes.get_dropdown)
npairs (require :nvim-autopairs)
2022-04-20 14:27:26 +00:00
gitsigns (require :gitsigns)
repl (require :nifoc.repl)]
2022-04-05 19:57:44 +00:00
(fn map-entry [key cmd opts]
(vim.tbl_extend :keep {1 key 2 cmd} opts))
(fn mod.setup []
(keymap.set :n :<space> :<nop> {:noremap true})
(set vim.g.mapleader " ")
(set vim.opt.timeoutlen 500)
(legendary.bind_keymaps [(map-entry :<leader>o
telescope-nifoc.project-files
{:description "Find Files"})
(map-entry :<leader>s
#(telescope-builtin.live_grep telescope-ivy)
{:description "Live Grep"})
(map-entry :<leader>fn :<cmd>enew<CR>
{:description "New File"})
(map-entry :<leader>ut :<cmd>UndotreeToggle<CR>
{:description "Toggle Undotree"})
2022-04-20 14:27:26 +00:00
(map-entry :<leader>c repl.toggle-shell
{:description "Toggle Shell"})
2022-04-21 16:55:53 +00:00
(map-entry :<leader>cs
#(telescope-toggleterm.open telescope-dropdown)
{:description "Select Terminal"})
2022-04-20 14:27:26 +00:00
(map-entry :<leader>r repl.toggle-repl
{:description "Toggle REPL"})
2022-04-05 19:57:44 +00:00
;; Buffer
(map-entry :<leader>bl
#(telescope-builtin.buffers telescope-dropdown)
{:description "List Buffers"})
(map-entry :<leader>bn
:<cmd>BufferLineCycleNext<CR>
{:description "Next Buffer"})
(map-entry :<leader>bp
:<cmd>BufferLineCyclePrev<CR>
{:description "Previous Buffer"})
(map-entry :<leader>bf
#(telescope-builtin.current_buffer_fuzzy_find telescope-dropdown)
{:description "Find In Buffer"})
(map-entry :<leader>bt
#(telescope-builtin.treesitter telescope-dropdown)
{:description "Find Via Treesitter"})
;; Project
(map-entry :<leader>pt :<cmd>TodoTelescope<CR>
{:description "TODO Comments"})
;; VCS
(map-entry :<leader>vs
#(telescope-builtin.git_status telescope-ivy)
{:description "VCS Status"})
(map-entry :<leader>vb
#(telescope-builtin.git_branches telescope-dropdown)
{:description "List VCS Branches"})
(map-entry :<leader>vl gitsigns.blame_line
{:description "Blame Line"})
(map-entry :<leader>vn :<cmd>Neogit<CR>
{:description "Open Neogit"})
(map-entry :<leader>vc "<cmd>Neogit commit<CR>"
{:description "Neogit Commit"})
(map-entry :<leader>vp "<cmd>Neogit pull<CR>"
{:description "Neogit Pull"})
(map-entry :<leader>vP "<cmd>Neogit push<CR>"
{:description "Neogit Push"})
2022-04-06 14:32:24 +00:00
;; Legendary
(map-entry :<leader>lk #(legendary.find :keymaps)
{:description "Legendary Keymaps"})
(map-entry :<leader>lc #(legendary.find :commands)
{:description "Legendary Commands"})
(map-entry :<leader>la #(legendary.find :autocmds)
{:description "Legendary Autocmds"})
2022-04-05 19:57:44 +00:00
;; Debug
(map-entry :<leader>dli :<cmd>LspInfo<CR>
{:description "LSP Info"})
(map-entry :<leader>dlr :<cmd>LspRestart<CR>
{:description "LSP Restart"})
(map-entry :<leader>dt
:<cmd>TSPlaygroundToggle<CR>
{:description "Toggle Treetsitter Playground"})
(map-entry :<leader>dn
telescope.extensions.notify.notify
{:description "Display Notifications"})])
;; Other Mappings
(keymap.set :n :<CR> ":nohlsearch<CR><CR>" {:noremap true :silent true})
(keymap.set :i :<CR> npairs.autopairs_cr
{:noremap true :expr true :silent true})
(keymap.set :n :<A-Left> :b {:noremap true})
(keymap.set :n :<A-Right> :w {:noremap true})
(keymap.set :n :<S-Left> "^" {:noremap true})
(keymap.set :n :<S-Right> "$" {:noremap true})
(keymap.set :i :<A-Left> :<C-o>b {:noremap true})
(keymap.set :i :<A-Right> :<C-o>w {:noremap true})
(keymap.set :i :<S-Left> :<C-o>^ {:noremap true})
(keymap.set :i :<S-Right> :<C-o>$ {:noremap true})
(keymap.set :n :p "<Plug>(YankyPutAfter)")
(keymap.set :n :P "<Plug>(YankyPutBefore)")
(keymap.set :x :p substitute.visual)
(keymap.set :x :P "<Plug>(YankyPutBefore)")
(keymap.set :n :gp "<Plug>(YankyGPutAfter)")
(keymap.set :n :gP "<Plug>(YankyGPutBefore)")
(keymap.set :x :gp "<Plug>(YankyGPutAfter)")
(keymap.set :x :gP "<Plug>(YankyGPutBefore)")
(keymap.set :n :y "<Plug>(YankyYank)")
2022-04-17 19:44:56 +00:00
(keymap.set :x :y "<Plug>(YankyYank)"))
2022-04-05 19:57:44 +00:00
(fn mod.lsp-attach [client bufnr]
(legendary.bind_keymaps [(map-entry :<leader>t
#(telescope-builtin.lsp_document_symbols telescope-dropdown)
{:description "LSP Document Symbols"
:opts {:buffer bufnr}})
2022-04-10 21:47:39 +00:00
(map-entry :<leader>ld
#(telescope-builtin.diagnostics (vim.tbl_extend :keep
telescope-ivy
2022-04-20 14:27:26 +00:00
{: bufnr}))
2022-04-05 19:57:44 +00:00
{:description "LSP Document Diagnostics"
:opts {:buffer bufnr}})
(map-entry :<leader>lca
#(telescope-builtin.lsp_code_actions telescope-dropdown)
{:description "LSP Code Action"
:opts {:buffer bufnr}})
(map-entry :<leader>lfr
2022-04-10 21:47:39 +00:00
#(telescope-builtin.lsp_references telescope-dropdown)
2022-04-05 19:57:44 +00:00
{:description "Find References"
:opts {:buffer bufnr}})
(map-entry :<leader>lfd
2022-04-10 21:47:39 +00:00
#(telescope-builtin.lsp_definitions telescope-dropdown)
2022-04-05 19:57:44 +00:00
{:description "Find Definitions"
:opts {:buffer bufnr}})
2022-04-10 21:58:10 +00:00
(map-entry :<leader>lfi
#(telescope-builtin.lsp_implementations telescope-dropdown)
{:description "Find Implementations"
:opts {:buffer bufnr}})
2022-04-05 19:57:44 +00:00
(map-entry :K vim.lsp.buf.hover
{:description "Show Documentation"
2022-04-06 14:32:24 +00:00
:opts {:buffer bufnr}})
(map-entry :F :<cmd>Format<CR>
{:description "Format Buffer"
2022-04-05 19:57:44 +00:00
:opts {:buffer bufnr}})]))
2022-04-20 14:27:26 +00:00
(fn mod.terminal-open [bufnr]
(let [map-opts {:noremap true :buffer bufnr}]
(keymap.set :t :<esc> "<C-\\><C-n>" map-opts)
(keymap.set :t :<C-h> "<C-\\><C-n><C-W>h" map-opts)
(keymap.set :t :<C-j> "<C-\\><C-n><C-W>j" map-opts)
(keymap.set :t :<C-k> "<C-\\><C-n><C-W>k" map-opts)
(keymap.set :t :<C-l> "<C-\\><C-n><C-W>l" map-opts)))
2022-04-05 19:57:44 +00:00
mod)