local utils = require "core.utils" local map = utils.map local cmd = vim.cmd local user_cmd = vim.api.nvim_create_user_command -- This is a wrapper function made to disable a plugin mapping from chadrc -- If keys are nil, false or empty string, then the mapping will be not applied -- Useful when one wants to use that keymap for any other purpose -- Don't copy the replaced text after pasting in visual mode map("v", "p", "p:let @+=@0") -- 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 map({ "n", "x", "o" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map({ "n", "x", "o" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) map("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) -- use ESC to turn off search highlighting map("n", "", " :noh ") -- move cursor within insert mode map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "^i") -- navigation between windows map("n", "", "h") map("n", "", "l") map("n", "", "k") map("n", "", "j") map("n", "x", function() require("core.utils").close_buffer() end) map("n", "", " :%y+ ") -- copy whole file content map("n", "", " :enew ") -- new buffer map("n", "b", " :tabnew ") -- new tabs map("n", "n", " :set nu! ") map("n", "rn", " :set rnu! ") -- relative line numbers map("n", "", " :w ") -- ctrl + s to save file -- terminal mappings -- get out of terminal mode map("t", { "jk" }, "") -- Add Packer commands because we are not loading it at startup local packer_cmd = function(callback) return function() require "plugins" require("packer")[callback]() end end -- snapshot stuff user_cmd("PackerSnapshot", function(info) require "plugins" require("packer").snapshot(info.args) end, { nargs = "+" }) user_cmd("PackerSnapshotDelete", function(info) require "plugins" require("packer.snapshot").delete(info.args) end, { nargs = "+" }) user_cmd("PackerSnapshotRollback", function(info) require "plugins" require("packer").rollback(info.args) end, { nargs = "+" }) user_cmd("PackerClean", packer_cmd "clean", {}) user_cmd("PackerCompile", packer_cmd "compile", {}) user_cmd("PackerInstall", packer_cmd "install", {}) user_cmd("PackerStatus", packer_cmd "status", {}) user_cmd("PackerSync", packer_cmd "sync", {}) user_cmd("PackerUpdate", packer_cmd "update", {}) -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" map("n", "uu", " :NvChadUpdate ") -- load overriden misc mappings require("core.utils").load_config().mappings.misc() local M = {} -- below are all plugin related mappings M.bufferline = function() map("n", "", " :BufferLineCycleNext ") map("n", "", " :BufferLineCyclePrev ") end M.comment = function() map("n", "/", " :lua require('Comment.api').toggle_current_linewise()") map("v", "/", " :lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") end M.lspconfig = function() -- See ` :help vim.lsp.*` for documentation on any of the below functions map("n", "gD", function() vim.lsp.buf.declaration() end) map("n", "gd", function() vim.lsp.buf.definition() end) map("n", "K", function() vim.lsp.buf.hover() end) map("n", "gi", function() vim.lsp.buf.implementation() end) map("n", "", function() vim.lsp.buf.signature_help() end) map("n", "D", function() vim.lsp.buf.type_definition() end) map("n", "ra", function() vim.lsp.buf.rename() end) map("n", "ca", function() vim.lsp.buf.code_action() end) map("n", "gr", function() vim.lsp.buf.references() end) map("n", "f", function() vim.diagnostic.open_float() end) map("n", "[d", function() vim.diagnostic.goto_prev() end) map("n", "d]", function() vim.diagnostic.goto_next() end) map("n", "q", function() vim.diagnostic.setloclist() end) map("n", "fm", function() vim.lsp.buf.formatting() end) map("n", "wa", function() vim.lsp.buf.add_workspace_folder() end) map("n", "wr", function() vim.lsp.buf.remove_workspace_folder() end) map("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end) end M.nvimtree = function() map("n", "", " :NvimTreeToggle ") map("n", "e", " :NvimTreeFocus ") end M.telescope = function() map("n", "fb", " :Telescope buffers ") map("n", "ff", " :Telescope find_files ") map("n", "fa", " :Telescope find_files follow=true no_ignore=true hidden=true ") map("n", "cm", " :Telescope git_commits ") map("n", "gt", " :Telescope git_status ") map("n", "fh", " :Telescope help_tags ") map("n", "fw", " :Telescope live_grep ") map("n", "fo", " :Telescope oldfiles ") map("n", "th", " :Telescope themes ") map("n", "tk", " :Telescope keymaps ") -- pick a hidden term map("n", "W", " :Telescope terms ") end return M