-- n, v, i, t = mode names local M = {} M.general = { i = { -- go to beginning and end [""] = { "^i", "Beginning of line" }, [""] = { "", "End of line" }, -- navigate within insert mode [""] = { "", "Move left" }, [""] = { "", "Move right" }, [""] = { "", "Move down" }, [""] = { "", "Move up" }, }, n = { ["n"] = { ":noh ", "Clear highlights" }, ["rr"] = { ":source $MYVIMRC", "Reload config file" }, -- switch between windows [""] = { "h", "Window left" }, [""] = { "l", "Window right" }, [""] = { "j", "Window down" }, [""] = { "k", "Window up" }, -- [""] = { " tab Git diff %", "Git diff this file" }, [""] = { " DiffviewOpen -- %", "Git diff this file" }, [""] = { " DiffviewFileHistory %", "Git history diff this file" }, [""] = { " DiffviewClose", "Close git diff" }, -- [""] = { " tab Git diff", "Git diff global" }, [""] = { " DiffviewOpen", "Git diff global" }, [""] = { ":DiffviewOpen HEAD~", "Show last N commits" }, ["gd"] = { " DiffviewClose", "Git diff close" }, -- save [""] = { " w ", "Save file" }, -- Copy all -- [""] = { " %y+ ", "Copy whole file" }, -- Quit [""] = { " q! ", "Force quit window" }, -- line numbers -- ["n"] = { " set nu! ", "Toggle line number" }, -- ["rn"] = { " set rnu! ", "Toggle relative number" }, -- allow moving the cursor through wrapped lines with j, k, and -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- empty mode is same as using :map -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } }, -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } }, -- [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } }, -- [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } }, ["y"] = {" :w! /tmp/vimtmp", "Save into a global tmp file"}, ["p"] = {" :r! cat /tmp/vimtmp", "Restore from the global tmp file"}, -- new buffer -- ["b"] = { " enew ", "New buffer" }, -- ["ch"] = { " NvCheatsheet ", "Mapping cheatsheet" }, }, t = { [""] = { vim.api.nvim_replace_termcodes("", true, true, true), "Escape terminal mode" }, }, v = { -- [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } }, -- [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } }, }, x = { -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } }, -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } }, -- Don't copy the replaced text after pasting in visual mode -- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#alternative_mapping_for_paste ["p"] = { 'p:let @+=@0:let @"=@0', "Dont copy replaced text", opts = { silent = true } }, }, } M.customstuffs = { n = { [""] = { "o", "Insert new line below" }, [""] = { "O", "Insert new line above" }, [""] = { " vertical topleft Git vertical resize 50", "Show Git status on a left pane" }, [""] = { " tabprevious", "Previous tab" }, [""] = { " tabnext", "Next tab" }, [""] = { " Flog -all", "Show git tree" }, [""] = { " tab Git show -", "Git show N last commits" }, [""] = { " TagbarToggle", "Show tagbar" }, ["ra"] = { " call VrcQuery()", "Call REST endpoint" }, ["dl"] = { "0d$", "Delete line from start" }, ["gp"] = { " Git pull", "Git pull" }, ["gnb"] = { ":Git checkout -b ", "Checkout to a new branch" }, ["gri"] = { ":Git rebase -i HEAD~", "Git rebase interactive from HEAD" }, ["mkd"] = { "lua vim.api.nvim_create_user_command('PeekOpen', require('peek').open, {})", "Open markdown preview" }, ["mkc"] = { "lua vim.api.nvim_create_user_command('PeekClose', require('peek').close, {})", "Open markdown preview" }, ["n"] = { "nzz", "Next + auto center" }, ["N"] = { "Nzz", "Previous + auto center" }, ["("] = { "(zz", "Previous + auto center" }, [")"] = { ")zz", "Previous + auto center" }, ["{"] = { "{zz", "Previous + auto center" }, ["}"] = { "}zz", "Previous + auto center" }, ["[["] = { "[[zz", "Previous + auto center" }, ["]]"] = { "]]zz", "Previous + auto center" }, -- Mappings: TODO -- "trim(system('git branch --show-current 2>/dev/null'))" -- ["tt"] = { ":call append(line('.') - 1, repeat(' ', indent('.')) . '# TODO-' . trim(system('git branch --show-current 2>/dev/null')) . ': ' . input('Comment >'))", "Add TODO comment + add to quickfix list" }, ["tt"] = { ":call append(line('.') - 1, repeat(' ', indent('.')) . '# TODO: ' . input('Comment >'))", "Add TODO comment + add to quickfix list" }, ["ww"] = { ":lua require('nvim-window').pick()", "Pick window to goto" }, ["wm"] = { ":WinShift", "Enter move window mode" }, ["ws"] = { ":WinShift swap", "Swap window, with selection" }, ["gg"] = { ":LazyGit", "Open lazygit" }, }, v = { ["n"] = { "nzz", "Next + auto center" }, ["N"] = { "Nzz", "Previous + auto center" }, ["("] = { "(zz", "Previous + auto center" }, [")"] = { ")zz", "Previous + auto center" }, ["{"] = { "{zz", "Previous + auto center" }, ["}"] = { "}zz", "Previous + auto center" }, ["[["] = { "[[zz", "Previous + auto center" }, ["]]"] = { "]]zz", "Previous + auto center" }, }, } M.tabufline = { plugin = true, n = { -- cycle through buffers [""] = { function() require("nvchad_ui.tabufline").tabuflineNext() end, "Goto next buffer", }, [""] = { function() require("nvchad_ui.tabufline").tabuflinePrev() end, "Goto prev buffer", }, -- close buffer + hide terminal buffer ["x"] = { function() require("nvchad_ui.tabufline").close_buffer() end, "Close buffer", }, }, } M.comment = { plugin = true, -- toggle comment in both modes n = { ["ci"] = { function() require("Comment.api").toggle.linewise.current() end, "Toggle comment", }, }, v = { ["ci"] = { "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", "Toggle comment", }, }, } M.lspconfig = { plugin = true, -- See ` :help vim.lsp.*` for documentation on any of the below functions n = { ["gD"] = { function() vim.lsp.buf.declaration() end, "LSP declaration", }, ["gd"] = { function() vim.lsp.buf.definition() end, "LSP definition", }, ["K"] = { function() vim.lsp.buf.hover() end, "LSP hover", }, ["gi"] = { function() vim.lsp.buf.implementation() end, "LSP implementation", }, ["ls"] = { function() vim.lsp.buf.signature_help() end, "LSP signature help", }, ["D"] = { function() vim.lsp.buf.type_definition() end, "LSP definition type", }, ["ra"] = { function() require("nvchad_ui.renamer").open() end, "LSP rename", }, ["ca"] = { function() vim.lsp.buf.code_action() end, "LSP code action", }, ["gr"] = { function() vim.lsp.buf.references() end, "LSP references", }, ["f"] = { function() vim.diagnostic.open_float { border = "rounded" } end, "Floating diagnostic", }, ["[d"] = { function() vim.diagnostic.goto_prev({ float = { border = "rounded" }}) end, "Goto prev", }, ["]d"] = { function() vim.diagnostic.goto_next({ float = { border = "rounded" }}) end, "Goto next", }, -- ["q"] = { -- function() -- vim.diagnostic.setloclist() -- end, -- "Diagnostic setloclist", -- }, ["fm"] = { function() vim.lsp.buf.format { async = true } end, "LSP formatting", }, ["wa"] = { function() vim.lsp.buf.add_workspace_folder() end, "add workspace folder", }, ["wr"] = { function() vim.lsp.buf.remove_workspace_folder() end, "Remove workspace folder", }, ["wl"] = { function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, "List workspace folders", }, }, } M.nvimtree = { plugin = true, n = { -- toggle [""] = { " NvimTreeToggle ", "Toggle nvimtree" }, -- focus ["e"] = { " NvimTreeFocus ", "Focus nvimtree" }, }, } M.telescope = { plugin = true, n = { -- Resume [""] = { " Telescope resume ", "Resume" }, -- find [""] = { " Telescope find_files ", "Find files" }, [""] = { " Telescope find_files follow=true no_ignore=true hidden=true ", "Find all" }, [""] = { " Telescope live_grep ", "Live grep" }, [""] = { " Telescope buffers ", "Find buffers" }, ["fg"] = { " lua require('telescope.builtin').live_grep({default_text=vim.fn.getreg('/')}) ", "Live grep with actual search value as prefix" }, ["gf"] = { " lua require('telescope.builtin').find_files({default_text=vim.fn.getreg('/')}) ", "Live grep with actual search value as prefix" }, ["ac"] = { ":execute 'vimgrep' input('Pattern >', getreg('/')) '**/*' ", "add search term files in quickfix list" }, -- ["qr"] = { ":execute 'cdo' '%s/' . input('Search term >', getreg('/')) . '/' . input('Replace by >', getreg('')) . '/g | update' ", "Replace pattern in all quickfix list" }, ["qr"] = { ":cdo '%s/' . input('Search term >', getreg('/')) . '/' . input('Replace by >', '') . '/g | update' ", "Replace pattern in all quickfix list" }, ["br"] = { ":execute '%s/' . input('Search term >', getreg('/')) . '/' . input('Replace by >', '') . '/g | update' ", "Replace pattern in current buffer" }, ["ql"] = { " Telescope quickfix ", "Show quickfix list" }, ["qn"] = { ":cnext", "Jump to next in quickfix list" }, ["qp"] = { ":cprevious", "Jump to previous in quickfix list" }, ["ll"] = { " Telescope loclist ", "Show loclist list" }, ["ln"] = { ":lnext", "Jump to next in loclist" }, ["lp"] = { ":lprevious", "Jump to previous in loclist" }, ["fh"] = { " Telescope help_tags ", "Help page" }, ["fo"] = { " Telescope oldfiles ", "Find oldfiles" }, ["fz"] = { " Telescope current_buffer_fuzzy_find ", "Find in current buffer" }, ["wl"] = { " Telescope workspaces ", "Find workspaces" }, -- git --- Commits ["gc"] = { " lua require('custom.telescope').my_git_commits()", "Custom Git commits" }, --- Status ["gss"] = { " lua require('custom.telescope').my_git_status()", "Custom Git status" }, --- Stash ["gsh"] = { " Telescope git_stash", "Git stash" }, --- Branches ["gbb"] = { " Telescope git_branches", "Git branches" }, ["gbc"] = { " lua require('custom.telescope').my_git_bcommits()", "Custom Git branchs commits" }, -- pick a hidden term ["pt"] = { " Telescope terms ", "Pick hidden term" }, -- theme switcher ["th"] = { " Telescope themes ", "Nvchad themes" }, ["ma"] = { " Telescope marks ", "telescope bookmarks" }, -- History ["ch"] = { " Telescope command_history ", "telescope commands history" }, ["/"] = { " Telescope search_history ", "telescope search history" }, -- Diaglist: LSP diagnostics in quick/loc list ["dw"] = { "lua require('diaglist').open_all_diagnostics()", "Open all open buffers diagnostics in quickfix list" }, ["d0"] = { "lua require('diaglist').open_buffer_diagnostics()", "Open current buffer diagnostics in loclist list" }, }, } M.nvterm = { plugin = true, t = { -- toggle in terminal mode [""] = { function() require("nvterm.terminal").toggle "float" end, "Toggle floating term", }, [""] = { function() require("nvterm.terminal").toggle "horizontal" end, "Toggle horizontal term", }, [""] = { function() require("nvterm.terminal").toggle "vertical" end, "Toggle vertical term", }, }, n = { -- toggle in normal mode [""] = { function() require("nvterm.terminal").toggle "float" end, "Toggle floating term", }, [""] = { function() require("nvterm.terminal").toggle "horizontal" end, "Toggle horizontal term", }, [""] = { function() require("nvterm.terminal").toggle "vertical" end, "Toggle vertical term", }, -- new ["h"] = { function() require("nvterm.terminal").new "horizontal" end, "New horizontal term", }, ["v"] = { function() require("nvterm.terminal").new "vertical" end, "New vertical term", }, }, } M.whichkey = { plugin = true, n = { ["wK"] = { function() vim.cmd "WhichKey" end, "Which-key all keymaps", }, ["wk"] = { function() local input = vim.fn.input "WhichKey: " vim.cmd("WhichKey " .. input) end, "Which-key query lookup", }, }, } M.blankline = { plugin = true, n = { ["cc"] = { function() local ok, start = require("indent_blankline.utils").get_current_context( vim.g.indent_blankline_context_patterns, vim.g.indent_blankline_use_treesitter_scope ) if ok then vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start, 0 }) vim.cmd [[normal! _]] end end, "Jump to current context", }, }, } M.gitsigns = { plugin = true, n = { -- Navigation through hunks ["]c"] = { function() if vim.wo.diff then return "]c" end vim.schedule(function() require("gitsigns").next_hunk() end) return "" end, "Jump to next hunk", opts = { expr = true }, }, ["[c"] = { function() if vim.wo.diff then return "[c" end vim.schedule(function() require("gitsigns").prev_hunk() end) return "" end, "Jump to prev hunk", opts = { expr = true }, }, -- actions ["rh"] = { function() require("gitsigns").reset_hunk() end, "Reset hunk", }, ["ph"] = { function() require("gitsigns").preview_hunk() end, "Preview hunk", }, ["bb"] = { function() package.loaded.gitsigns.blame_line() end, "Blame line", }, ["td"] = { function() require("gitsigns").toggle_deleted() end, "Toggle deleted", }, }, } return M